LocalTransformer, HasLocalTransformer, IsChildRule

ID: 126

				
					using uCalcSoftware;

var uc = new uCalc();
// Note the change in section/div/h2
var t = uc.NewTransformer();

var rule = t.Pattern("<section>{body}</section>").SetStatementSensitive(false);
var section = rule.LocalTransformer;
section.FromTo("<h2>{text}</h2>", "<h1>====> {@Eval: UCase(text)} <====</h1>");
section.SkipOver("&{entity};");
var ch = section.FromTo("<p>{text}</p>", "<p>SELECTED: {text}</p>");

Console.WriteLine($"Has a local transformer: {rule.HasLocalTransformer}");
Console.WriteLine($"rule is a child rule: {rule.IsChildRule}");
Console.WriteLine($"ch is a child rule: {ch.IsChildRule}");

var HtmlText =
"""

<div class="article" data-id="1">
  <h2>Article One</h2>
  <p>This is the first article.</p>
</div>

<div class="article" data-id="2">
  <h2>Article Two</h2>
  <p>This is the second article.</p>
</div>

<section>
  <div class="article" data-id="3">
    <h2>Article Three</h2>
    <p>This one is inside a &lt;section&gt;.</p>
  </div>
</section>

<div class="article" data-id="4">
  <h2>Article Four</h2>
  <p>This is the fourth article.</p>
</div>

""";

t.Text = HtmlText;
t.Transform();
Console.WriteLine(t.Text);


				
			
Has a local transformer: True
rule is a child rule: False
ch is a child rule: True

<div class="article" data-id="1">
  <h2>Article One</h2>
  <p>This is the first article.</p>
</div>

<div class="article" data-id="2">
  <h2>Article Two</h2>
  <p>This is the second article.</p>
</div>

<section>
  <div class="article" data-id="3">
    <h1>====> ARTICLE THREE <====</h1>
    <p>SELECTED: This one is inside a &lt;section&gt;.</p>
  </div>
</section>

<div class="article" data-id="4">
  <h2>Article Four</h2>
  <p>This is the fourth article.</p>
</div>
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

#define tf(IsTrue) ((IsTrue) ? "True" : "False")

int main() {
   uCalc uc;
   // Note the change in section/div/h2
   auto t = uc.NewTransformer();

   auto rule = t.Pattern("<section>{body}</section>").SetStatementSensitive(false);
   auto section = rule.LocalTransformer();
   section.FromTo("<h2>{text}</h2>", "<h1>====> {@Eval: UCase(text)} <====</h1>");
   section.SkipOver("&{entity};");
   auto ch = section.FromTo("<p>{text}</p>", "<p>SELECTED: {text}</p>");

   cout << "Has a local transformer: " << tf(rule.HasLocalTransformer()) << endl;
   cout << "rule is a child rule: " << tf(rule.IsChildRule()) << endl;
   cout << "ch is a child rule: " << tf(ch.IsChildRule()) << endl;

   auto HtmlText =
   R"(
<div class="article" data-id="1">
  <h2>Article One</h2>
  <p>This is the first article.</p>
</div>

<div class="article" data-id="2">
  <h2>Article Two</h2>
  <p>This is the second article.</p>
</div>

<section>
  <div class="article" data-id="3">
    <h2>Article Three</h2>
    <p>This one is inside a &lt;section&gt;.</p>
  </div>
</section>

<div class="article" data-id="4">
  <h2>Article Four</h2>
  <p>This is the fourth article.</p>
</div>
)";

   t.Text(HtmlText);
   t.Transform();
   cout << t.Text() << endl;


}
				
			
Has a local transformer: True
rule is a child rule: False
ch is a child rule: True

<div class="article" data-id="1">
  <h2>Article One</h2>
  <p>This is the first article.</p>
</div>

<div class="article" data-id="2">
  <h2>Article Two</h2>
  <p>This is the second article.</p>
</div>

<section>
  <div class="article" data-id="3">
    <h1>====> ARTICLE THREE <====</h1>
    <p>SELECTED: This one is inside a &lt;section&gt;.</p>
  </div>
</section>

<div class="article" data-id="4">
  <h2>Article Four</h2>
  <p>This is the fourth article.</p>
</div>
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Note the change in section/div/h2
      Dim t = uc.NewTransformer()
      
      Dim rule = t.Pattern("<section>{body}</section>").SetStatementSensitive(false)
      Dim section = rule.LocalTransformer
      section.FromTo("<h2>{text}</h2>", "<h1>====> {@Eval: UCase(text)} <====</h1>")
      section.SkipOver("&{entity};")
      Dim ch = section.FromTo("<p>{text}</p>", "<p>SELECTED: {text}</p>")
      
      Console.WriteLine($"Has a local transformer: {rule.HasLocalTransformer}")
      Console.WriteLine($"rule is a child rule: {rule.IsChildRule}")
      Console.WriteLine($"ch is a child rule: {ch.IsChildRule}")
      
      Dim HtmlText =
      "
<div class=""article"" data-id=""1"">
  <h2>Article One</h2>
  <p>This is the first article.</p>
</div>

<div class=""article"" data-id=""2"">
  <h2>Article Two</h2>
  <p>This is the second article.</p>
</div>

<section>
  <div class=""article"" data-id=""3"">
    <h2>Article Three</h2>
    <p>This one is inside a &lt;section&gt;.</p>
  </div>
</section>

<div class=""article"" data-id=""4"">
  <h2>Article Four</h2>
  <p>This is the fourth article.</p>
</div>
"
      
      t.Text = HtmlText
      t.Transform()
      Console.WriteLine(t.Text)
      
      
   End Sub
End Module
				
			
Has a local transformer: True
rule is a child rule: False
ch is a child rule: True

<div class="article" data-id="1">
  <h2>Article One</h2>
  <p>This is the first article.</p>
</div>

<div class="article" data-id="2">
  <h2>Article Two</h2>
  <p>This is the second article.</p>
</div>

<section>
  <div class="article" data-id="3">
    <h1>====> ARTICLE THREE <====</h1>
    <p>SELECTED: This one is inside a &lt;section&gt;.</p>
  </div>
</section>

<div class="article" data-id="4">
  <h2>Article Four</h2>
  <p>This is the fourth article.</p>
</div>