Tcl Library Source Code

View Ticket
Login
Ticket UUID: 0d23817f75c666c912a812c6f1125b3406055f59
Title: In package Markdown when a boolean attribute is used in an embedded html element, the rest of the markdown text is ignored.
Type: Bug Version: 1.19
Submitter: LawrenceWoodman Created on: 2018-06-09 06:27:36
Subsystem: markdown Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2022-05-05 15:36:39
Resolution: Fixed Closed By: aku
    Closed on: 2022-05-05 12:26:55
Description:
 	

In package Markdown when a boolean attribute is used in an embedded html element, the rest of the markdown text is ignored.  The following code demonstrates:

package require tcltest
namespace import tcltest::*
package require Markdown

test booleanattribute {embedded html using a boolean attribute} -body {
  Markdown::convert {
hello

<div allowfullscreen></div>

hello again
  }
} -result {<p>hello</p>

<div allowfullscreen></div>

<p>hello again</p>}
User Comments: aku added on 2022-05-05 15:36:39:

Markdown should work now.


aku added on 2022-05-05 12:26:55:

Fixed with commit [31b56b6b47] using Torsten's patch and test cases, with thanks.


torstenberg added on 2022-05-05 11:41:50:
Thanks! With respect to markdown in ticket. You are using version 2.19 which can do it. You just need to configure it under "Admin > Tickets" and the customise the template for "New Ticket Page" accordingly. The default template supports ...

if {$mutype eq "HTML"} {
       set mimetype "text/html"
     } elseif {$mutype eq "Wiki"} {
       set mimetype "text/x-fossil-wiki"
     } elseif {$mutype eq "Markdown"} {
       set mimetype text/x-markdown
     } elseif {$mutype eq {[links only]}} {
       set mimetype "text/x-fossil-plain"
     } else {
       set mimetype "text/plain"
     }

aku added on 2022-05-05 11:23:52:

Thank you Torsten for the work. Will integrate the proposed changes and tests later today.

Wrt Markdown in ticket comments ... Will have to ask Richard if fossil supports it, since when (version), and if the fossil on core is suitable.


torstenberg added on 2022-05-05 08:26:48:
OK, got it. The `re_htmltag` regular expression on line 407 (in trunk) was the problem. It did not allow for html attributes without assignment to a value. This is why `<div allowfullscreen="1"></div>` would work but `<div allowfullscreen></div>` would not work. The fix is to replace the current regular expression on line 407 like this:

```
set re_htmltag {<(/?)(\w+)(?:\s+\w+(?:=\"[^\"]+\"|'[^']+')?)*\s*>}
```

I suggest to add these two tests to markdown.test to catch the cases:

```
test div-1.1 {embedded html on a line surrounded by empty lines having html attribute without value} -body {
    convert {
        hello

        <div allowfullscreen></div>

        hello again
    }
} -result {
    <p>hello</p>

    <div allowfullscreen></div>

    <p>hello again</p>
}


test div-1.2 {embedded html on a line surrounded by empty lines having html attribute with value} -body {
    convert {
        hello

        <div allowfullscreen="1"></div>

        hello again
    }
} -result {
    <p>hello</p>

    <div allowfullscreen="1"></div>

    <p>hello again</p>
}
```

And while we are in this region of the code, we could simplify lines 436-439 slightly to:

```
                    while {$index < $no_lines && [is_empty_line [lindex $lines $index]]} {
                        incr index
                    }
```

Still, the `<div>` causes trouble in inline use within markdown. I will sumbit another ticket for that with some test (and no current solution) and propose to mark this as knownbug for the upcoming release.

(And by the way: wouldn't it be nice to have markdown for the tickets here??)

torstenberg added on 2022-05-04 06:47:38:
This is not an easy one. It seems that the whole HTML tag parsing is wrong at least on <div> tags as these are block elements and are not treated as such. E.g. a <div> specified in the middle of a line results in a <div> inside a <p>. I am investigating this further.



All these (new) tests fails:

test div-1.1 {embedded html on a line surrounded by white space} -body {
    convert {
        hello

        <div allowfullscreen></div>

        hello again
    }
} -result {
    <p>hello</p>

    <div allowfullscreen></div>

    <p>hello again</p>
}

test div-1.2 {embedded div on a line in a paragraph} -body {
    convert {
        hello
        <div allowfullscreen></div>
        hello again
    }
} -result {
    <p>hello</p>

    <div allowfullscreen></div>

    <p>hello again</p>
}

test div-1.3 {embedded div with attribute on a line in a paragraph} -body {
    convert {
        hello
        <div allowfullscreen="1"></div>
        hello again
    }
} -result {
    <p>hello</p>

    <div allowfullscreen="1"></div>

    <p>hello again</p>
}

test div-1.4 {single div with attribute} -body {
    convert {
        <div allowfullscreen="1"></div>
    }
} -result {
    <div allowfullscreen="1"></div>
}


test div-1.5 {single div within an inline} -body {
    convert {
        hello <div>blurb</div> again
    }
} -result {
    hello
	 <div>blurb</div>
    <p>again</p>
}

aku added on 2022-03-30 09:30:23:
@ torstenberg - Did you have success in creating a fix for this ?

torstenberg added on 2021-09-20 21:50:09:
I (torstenberg) am now working on this one.

Changing the `<div>` line in the test to `<div allowfullscreen=1></div>` makes the test pass. So, the missing "=1" make the parser fail here.

aku added on 2018-07-09 19:21:54:
Sean, can you look into this, please ?
This might have to be reported to Caius as well.
Or maybe a fix ported over if they already have one.