replaceing * by *
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simon Petit 2024-11-17 17:46:42 +01:00
parent 8ef470c84d
commit 91a34681be
2 changed files with 12 additions and 12 deletions

View File

@ -158,19 +158,19 @@ Whenever the pattern is found, two global variables are filled :
For the following, `line` represents the line processed by the function, as the following `while` loops are actually part of a single function.
This way `match(line, /\*([^*]+)\*/)` matches a string surrounded by two `*`, corresponding to an emphasis text.
This way `match(line, /\*([^*]+)\*/)` matches a string surrounded by two `*`, corresponding to an emphasis text.
The `*` are espaced are thez are special characters, and the *group* is inside the parenthesis.
To matche several instances of emphasis text within a line, a simple `while` will do the trick.
We now only have to insert html tags `<em>` are the right space around the matched text, and we are good to go.
We now only have to insert html tags `&lt;em&gt;` are the right space around the matched text, and we are good to go.
We can save the global variables `RSTART` and `RLENGTH` for further use, in case they were to be change. Using them we also can extract the
matched substrings and reconstruct the actual html string :
while (match(line, /\*([^*]+)\*/)) {
while (match(line, /\&#42;([^&#42;]+)\&#42;/)) {
start = RSTART
end = RSTART + RLENGTH - 1
# Build the result: before match, <em>, content, </em>, after match
line = substr(line, 1, start-1) "<em>" substr(line, start+1, RLENGTH-2) "</em>" substr(line, end+1)
# Build the result: before match, &lt;em&gt;, content, &lt;/em&gt;, after match
line = substr(line, 1, start-1) "&lt;em&gt;" substr(line, start+1, RLENGTH-2) "&lt;/em&gt;" substr(line, end+1)
}
We now can repeat the pattern for all inline fonctionnalities, e.g. strong and code.
@ -197,7 +197,7 @@ It is possible to apply the match fonction on this `matched` string, and extract
As the link text and the url are stored, using the variables `start` and `end`, it is easy to reconstruct the html line :
line = substr(line, 1, start-1) "<a href=\"" matched_url "\">" matched_link "</a>" substr(line, end+1)
line = substr(line, 1, start-1) "&lt;a href=\"" matched_url "\"&gt;" matched_link "&lt;/a&gt;" substr(line, end+1)
The inline parsing function is now complete, all we have to do it apply is systematically on the text within html tags and this finished the markdown parser.

View File

@ -158,17 +158,17 @@ function last() {
<li>RLENGTH: the length of the matched *group*</li>
</ul>
<p>For the following, `line` represents the line processed by the function, as the following `while` loops are actually part of a single function.</p>
<p>This way `match(line, /\<em>([^</em>]+)\<em>/)` matches a string surrounded by two `</em>`, corresponding to an emphasis text.</p>
<p>This way `match(line, /&#42;([^&#42;]+)&#42;/)` matches a string surrounded by two `&#42;`, corresponding to an emphasis text.</p>
<p>The `<em>` are espaced are thez are special characters, and the </em>group* is inside the parenthesis.</p>
<p>To matche several instances of emphasis text within a line, a simple `while` will do the trick.</p>
<p>We now only have to insert html tags `<em>` are the right space around the matched text, and we are good to go.</p>
<p>We now only have to insert html tags `&lt;em&gt;` are the right space around the matched text, and we are good to go.</p>
<p>We can save the global variables `RSTART` and `RLENGTH` for further use, in case they were to be change. Using them we also can extract the </p>
<p>matched substrings and reconstruct the actual html string :</p>
<pre><code>while (match(line, /\*([^*]+)\*/)) {
<pre><code>while (match(line, /&#42;([^&#42;]+)&#42;/)) {
start = RSTART
end = RSTART + RLENGTH - 1
# Build the result: before match, <em>, content, </em>, after match
line = substr(line, 1, start-1) "<em>" substr(line, start+1, RLENGTH-2) "</em>" substr(line, end+1)
# Build the result: before match, &lt;em&gt;, content, &lt;/em&gt;, after match
line = substr(line, 1, start-1) "&lt;em&gt;" substr(line, start+1, RLENGTH-2) "&lt;/em&gt;" substr(line, end+1)
}
</code>
</pre>
@ -192,7 +192,7 @@ if (match(matched, /\([^\)]+\)/)) {
</code>
</pre>
<p>As the link text and the url are stored, using the variables `start` and `end`, it is easy to reconstruct the html line :</p>
<pre><code>line = substr(line, 1, start-1) "<a href="" matched_url "">" matched_link "</a>" substr(line, end+1)
<pre><code>line = substr(line, 1, start-1) "&lt;a href="" matched_url ""&gt;" matched_link "&lt;/a&gt;" substr(line, end+1)
</code>
</pre>
<p>The inline parsing function is now complete, all we have to do it apply is systematically on the text within html tags and this finished the markdown parser.</p>