diff --git a/drafts/published/awk_for_static_site_generation.md b/drafts/published/awk_for_static_site_generation.md index a9189e8..5a24c5b 100644 --- a/drafts/published/awk_for_static_site_generation.md +++ b/drafts/published/awk_for_static_site_generation.md @@ -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 `` 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 matched substrings and reconstruct the actual html string : - while (match(line, /\*([^*]+)\*/)) { + while (match(line, /\*([^*]+)\*/)) { start = RSTART end = RSTART + RLENGTH - 1 - # Build the result: before match, , content, , after match - line = substr(line, 1, start-1) "" substr(line, start+1, RLENGTH-2) "" substr(line, end+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) } 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) "" matched_link "" 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. diff --git a/posts/awk_for_static_site_generation.html b/posts/awk_for_static_site_generation.html index 1f20d20..8fa26f2 100644 --- a/posts/awk_for_static_site_generation.html +++ b/posts/awk_for_static_site_generation.html @@ -158,17 +158,17 @@ function last() {
  • RLENGTH: the length of the matched *group*
  • 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 `` 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

    matched substrings and reconstruct the actual html string :

    -
    while (match(line, /\*([^*]+)\*/)) {
    +
    while (match(line, /*([^*]+)*/)) {
         start = RSTART
         end = RSTART + RLENGTH - 1
    -    # Build the result: before match, , content, , after match
    -    line = substr(line, 1, start-1) "" substr(line, start+1, RLENGTH-2) "" substr(line, end+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)
     }
     
     
    @@ -192,7 +192,7 @@ if (match(matched, /\([^\)]+\)/)) {

    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) "" matched_link "" 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.