From: Paul Hänsch Date: Tue, 4 Nov 2025 18:02:08 +0000 (+0100) Subject: Markdown Bugfix: use correct HTML escaping for heading id's (instead of URL escaping) X-Git-Url: http://git.plutz.net/?a=commitdiff_plain;h=aa6ce00f86f035e3cc4c2603efcd96a76082dcfa;p=cgilite Markdown Bugfix: use correct HTML escaping for heading id's (instead of URL escaping) --- diff --git a/markdown.awk b/markdown.awk index 744bcba..b079bbe 100755 --- a/markdown.awk +++ b/markdown.awk @@ -106,13 +106,13 @@ function HTML ( text ) { return text; } -function URL ( text, sharp ) { +function URL ( text ) { gsub( /&/, "%26", text ); gsub( /"/, "%22", text ); gsub( /'/, "%27", text ); gsub( /`/, "%60", text ); gsub( /\?/, "%3F", text ); - if (sharp) gsub( /#/, "%23", text ); + gsub( /#/, "%23", text ); gsub( /\[/, "%5B", text ); gsub( /\]/, "%5D", text ); gsub( / /, "%20", text ); @@ -383,7 +383,7 @@ function inline( line, LOCAL, len, text, code, href, guard, ret ) { return ret; } -function headline( hlvl, htxt, attrib, LOCAL, sec, n, HL) { +function headline( hlvl, htxt, attrib, LOCAL, sec, n, hid, hid2, HL) { # match(hstack, /([0-9]+( [0-9]+){5})$/); split( substr(hstack, RSTART), HL); match(hstack, /([0-9]+( [0-9]+)( [0-9]+)( [0-9]+)( [0-9]+)( [0-9]+))$/); split( substr(hstack, RSTART), HL); @@ -392,7 +392,10 @@ function headline( hlvl, htxt, attrib, LOCAL, sec, n, HL) { hid = ""; for ( n = 2; n <= blvl; n++) { hid = hid BL[n] "/"; } hid = hid HL[1]; for ( n = 2; n <= hlvl; n++) { hid = hid "." HL[n] ; } - hid = hid ":" URL(htxt, 1); + hid = hid ":" HTML(htxt); # anchor for TOC + # hid2 = ":" HTML(htxt); # anchor for permalink + # while ( headings[hid2] ) { n = n ? 2 : n + 1; hid2 = ":" HTML(htxt) "/" n; } + # headings[hid2] = true; # sub(/([0-9]+( [0-9]+){5})$/, "", hstack); sub(/([0-9]+( [0-9]+)( [0-9]+)( [0-9]+)( [0-9]+)( [0-9]+))$/, "", hstack); diff --git a/tests-markdown.sh b/tests-markdown.sh index 30442cc..3e033dd 100755 --- a/tests-markdown.sh +++ b/tests-markdown.sh @@ -1,6 +1,6 @@ #!/bin/sh -runtimes="gawk busybox mawk goawk" +runtimes="${runtimes:-gawk busybox mawk goawk}" BR=' ' @@ -219,45 +219,45 @@ assert '![Testbild *ARD*](Test Bild.jpg){tv ard function-check}' \ # Headings assert 'Heading first Order ============' \ -'

Heading first Order

+'

Heading first Order

' \ 'Heading h1' assert 'Heading first Order {.foo #bar} ============' \ -'

Heading first Order

+'

Heading first Order

' \ 'Heading h1 + attributes' assert 'Heading second Order ------------' \ -'

Heading second Order

+'

Heading second Order

' \ 'Heading h2' assert 'Heading second Order {.foo #bar} ------------' \ -'

Heading second Order

+'

Heading second Order

' \ 'Heading h2 + attributes' assert '#### Heading four' \ -'

Heading four

+'

Heading four

' \ 'Heading arbitrary' assert '###Heading three ######' \ -'

Heading three

+'

Heading three

' \ 'Heading arbitrary' assert '### Heading three ## {foo bar}' \ -'

Heading three

+'

Heading three

' \ 'Heading arbitrary + attributes' assert '# Heading \# # {foo bar}' \ -'

Heading #

+'

Heading #

' \ 'Heading arbitrary + attributes' @@ -397,9 +397,9 @@ sub bar ' \ '

foo

bar

-

sub bar

-

sub sub sub

-

sub2 bar

+

sub bar

+

sub sub sub

+

sub2 bar

' \ 'Headline Nesting' @@ -533,7 +533,7 @@ Tests ----- [Link with Title](https://en.wikipedia.org/wiki/Markdown "Markdown in Wikipedia"), *emphasis*, **strong**, **strong containing *emphasis***, `inline code`, `` code with `backticks` ``. See more tests [here](./tests/).' \ '

Markdown.awk

-

Supported Features / TODO:

+

Supported Features / TODO:

  • done
  • todo
  • @@ -541,7 +541,7 @@ Tests
  • ? unsure (whether to implement)
  • partial
-

Basic Markdown - Block elements:

+

Basic Markdown - Block elements:

  • Paragraphs

      @@ -557,7 +557,7 @@ Tests
    • Horizontal rules
    • Verbatim HTML block (disabled by default)
    -

Basic Markdown - Inline elements:

+

Basic Markdown - Inline elements:

  • Links
  • Reference style links
  • @@ -571,7 +571,7 @@ Tests

NOTE: Set the environment variable MD_HTML=true to enable verbatim HTML

-

Extensions - Block elements:

+

Extensions - Block elements:

  • Automatic <section>-wrapping (custom)
  • ? Heading identifiers (php md, pandoc)

    @@ -610,7 +610,7 @@ Tests
  • Metadata blocks (custom)
  • Fenced Divs (pandoc)
-

Extensions - Inline elements:

+

Extensions - Inline elements:

  • Ignore embedded_underscores (php md, pandoc)
  • strikeout (pandoc)
  • @@ -718,15 +718,15 @@ Term 2 1. first list item 2. second list item' \ -'

    Headline First Order

    -

    Headline Second Order

    +'

    Headline First Order

    +

    Headline Second Order

    Code Block
     with indentation

    Blockquote

    like in an email

    -

    Headline 3rd order

    +

    Headline 3rd order

    • unordered List
    @@ -963,7 +963,7 @@ For additional examples, regarding permanent installation and configuration in w Syntax ------ -The wiki syntax is based on John Grubers [Markdown](https://daringfireball.net/projects/markdown/) with extensions borrowed from [Pandoc](https://pandoc.org/MANUAL%202.html#pandocs-markdown) and [PHP Markdown Extra](https://michelf.ca/projects/php-markdown/extra/). The Markdown parser is provided by [Cgilite](/software/cgilite/) and its full documentation can be looked at [here](/software/cgilite/markdown/). +The wiki syntax is based on John Grubers [Markdown](https://daringfireball.net/projects/markdown/) with extensions borrowed from [Pandoc](https://pandoc.org/MANUAL 2.html#pandocs-markdown) and [PHP Markdown Extra](https://michelf.ca/projects/php-markdown/extra/). The Markdown parser is provided by [Cgilite](/software/cgilite/) and its full documentation can be looked at [here](/software/cgilite/markdown/). <> @@ -1182,7 +1182,7 @@ visitors into handling GDPR "consent" forms.

    For additional examples, regarding permanent installation and configuration in webservers see installation/.

    Syntax

    -

    The wiki syntax is based on John Grubers Markdown with extensions borrowed from Pandoc and PHP Markdown Extra. The Markdown parser is provided by Cgilite and its full documentation can be looked at here.

    +

    The wiki syntax is based on John Grubers Markdown with extensions borrowed from Pandoc and PHP Markdown Extra. The Markdown parser is provided by Cgilite and its full documentation can be looked at here.

    include --nolink /[wiki]/editorhelp/

    Macros

    Also see → macros/

    @@ -1203,7 +1203,7 @@ visitors into handling GDPR "consent" forms.

    For an example, see the technical pages for this wiki.

    -

    Multiple Languages

    +

    Multiple Languages

    To enable a multilingual setup you must set a default language in your configuration environment:

    export LANGUAGE_DEFAULT=en
    @@ -1215,12 +1215,12 @@ visitors into handling GDPR "consent" forms.

    Header, footer, and error pages will be included from their respective language version, as will all macro includes, etc. Should a page not exist in a given language, the default page will be displayed instead. However, included elements will still be taken from the respective language version, possibly mixing languages between the selected user language and the default.

    -

    Constraints of the current implementation

    +

    Constraints of the current implementation

    • There can be only one default language, with no priority of different fallback languages
    • Page URLs can currently not be translated. Doing so would require a model for manually assigning translated page names and would not be trivial to use.
    -

    Developer Documentation

    +

    Developer Documentation

    How to write: