Practical: Creates a custom code block parser. `@QuoteSensitive(false)` is essential to allow the capture of content that contains its own quotes.
ID: 971
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
var source = """
Some text... [code]print("Hello, World!") // Quoted with "
var x = 'test';[/code] ...more text.
""";
// This rule must disable QuoteSensitive and StatementSensitive to correctly
// capture the multi-line block containing single and double quotes.
var rule = t.FromTo("'['code']'{content}'['/code']'", """
```
{content}
```
""");
rule.QuoteSensitive = false;
rule.StatementSensitive = false;
Console.WriteLine(t.Transform(source));
Some text... ```
print("Hello, World!") // Quoted with "
var x = 'test';
``` ...more text. using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); var source = """ Some text... [code]print("Hello, World!") // Quoted with " var x = 'test';[/code] ...more text. """; // This rule must disable QuoteSensitive and StatementSensitive to correctly // capture the multi-line block containing single and double quotes. var rule = t.FromTo("'['code']'{content}'['/code']'", """ ``` {content} ``` """); rule.QuoteSensitive = false; rule.StatementSensitive = false; Console.WriteLine(t.Transform(source));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
auto source = R"(Some text... [code]print("Hello, World!") // Quoted with "
var x = 'test';[/code] ...more text.)";
// This rule must disable QuoteSensitive and StatementSensitive to correctly
// capture the multi-line block containing single and double quotes.
auto rule = t.FromTo("'['code']'{content}'['/code']'", R"(```
{content}
```)");
rule.QuoteSensitive(false);
rule.StatementSensitive(false);
cout << t.Transform(source) << endl;
}
Some text... ```
print("Hello, World!") // Quoted with "
var x = 'test';
``` ...more text. #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); auto source = R"(Some text... [code]print("Hello, World!") // Quoted with " var x = 'test';[/code] ...more text.)"; // This rule must disable QuoteSensitive and StatementSensitive to correctly // capture the multi-line block containing single and double quotes. auto rule = t.FromTo("'['code']'{content}'['/code']'", R"(``` {content} ```)"); rule.QuoteSensitive(false); rule.StatementSensitive(false); cout << t.Transform(source) << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
Dim source = "Some text... [code]print(""Hello, World!"") // Quoted with ""
var x = 'test';[/code] ...more text."
'// This rule must disable QuoteSensitive and StatementSensitive to correctly
'// capture the multi-line block containing single and double quotes.
Dim rule = t.FromTo("'['code']'{content}'['/code']'", "```
{content}
```")
rule.QuoteSensitive = false
rule.StatementSensitive = false
Console.WriteLine(t.Transform(source))
End Sub
End Module
Some text... ```
print("Hello, World!") // Quoted with "
var x = 'test';
``` ...more text. Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() Dim source = "Some text... [code]print(""Hello, World!"") // Quoted with "" var x = 'test';[/code] ...more text." '// This rule must disable QuoteSensitive and StatementSensitive to correctly '// capture the multi-line block containing single and double quotes. Dim rule = t.FromTo("'['code']'{content}'['/code']'", "``` {content} ```") rule.QuoteSensitive = false rule.StatementSensitive = false Console.WriteLine(t.Transform(source)) End Sub End Module