This commit is contained in:
parent
8ef470c84d
commit
91a34681be
@ -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.
|
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.
|
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.
|
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 `<em>` 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
|
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 :
|
matched substrings and reconstruct the actual html string :
|
||||||
|
|
||||||
|
|
||||||
while (match(line, /\*([^*]+)\*/)) {
|
while (match(line, /\*([^*]+)\*/)) {
|
||||||
start = RSTART
|
start = RSTART
|
||||||
end = RSTART + RLENGTH - 1
|
end = RSTART + RLENGTH - 1
|
||||||
# Build the result: before match, <em>, content, </em>, after match
|
# 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)
|
line = substr(line, 1, start-1) "<em>" substr(line, start+1, RLENGTH-2) "</em>" substr(line, end+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
We now can repeat the pattern for all inline fonctionnalities, e.g. strong and code.
|
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 :
|
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) "<a href=\"" matched_url "\">" matched_link "</a>" 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.
|
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.
|
||||||
|
|
||||||
|
@ -158,17 +158,17 @@ function last() {
|
|||||||
<li>RLENGTH: the length of the matched *group*</li>
|
<li>RLENGTH: the length of the matched *group*</li>
|
||||||
</ul>
|
</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>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, /*([^*]+)*/)` matches a string surrounded by two `*`, 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>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>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 `<em>` 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>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>
|
<p>matched substrings and reconstruct the actual html string :</p>
|
||||||
<pre><code>while (match(line, /\*([^*]+)\*/)) {
|
<pre><code>while (match(line, /*([^*]+)*/)) {
|
||||||
start = RSTART
|
start = RSTART
|
||||||
end = RSTART + RLENGTH - 1
|
end = RSTART + RLENGTH - 1
|
||||||
# Build the result: before match, <em>, content, </em>, after match
|
# 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)
|
line = substr(line, 1, start-1) "<em>" substr(line, start+1, RLENGTH-2) "</em>" substr(line, end+1)
|
||||||
}
|
}
|
||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
@ -192,7 +192,7 @@ if (match(matched, /\([^\)]+\)/)) {
|
|||||||
</code>
|
</code>
|
||||||
</pre>
|
</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>
|
<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) "<a href="" matched_url "">" matched_link "</a>" substr(line, end+1)
|
||||||
</code>
|
</code>
|
||||||
</pre>
|
</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>
|
<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>
|
||||||
|
Loading…
Reference in New Issue
Block a user