gettalong / kramdown

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.
http://kramdown.gettalong.org
Other
1.72k stars 275 forks source link

Limited rendering of fraction entities #769

Open ashmaroli opened 2 years ago

ashmaroli commented 2 years ago

A Jekyll user brought to my notice that kramdown doesn't render fraction entities like other Markdown parsers (e.g. pandoc, Commonmarker, etc) do.

Local tests show that only ¼, ½ and ¾ are rendered whereas ⅓ (⅓), ⅔ (⅔), ⅘ (⅘) etc are not.

gettalong commented 2 years ago

I'm not sure where the problem is because of this:

$ kramdown
Some frac 1/2
^d
<p>Some frac 1/2</p>

There is no code in kramdown that converts 1/4, 1/2 and 3/4 to the corresponding fraction character.

Could you show what you did?

ashmaroli commented 2 years ago

Could you show what you did?

My test script:

require "kramdown"

list = []
(1..5).each do |i|
  list << ((i+1)..9).to_a.map { |n| "&frac#{i}#{n};" }.join(", ")
end
puts Kramdown::Document.new(list.join("\n\n")).to_html

# pasting output here for readers' convenience (extra linefeed stripped for compactness):
#
# <p>½, &amp;frac13;, ¼, &amp;frac15;, &amp;frac16;, &amp;frac17;, &amp;frac18;, &amp;frac19;</p>
# <p>&amp;frac23;, &amp;frac24;, &amp;frac25;, &amp;frac26;, &amp;frac27;, &amp;frac28;, &amp;frac29;</p>
# <p>¾, &amp;frac35;, &amp;frac36;, &amp;frac37;, &amp;frac38;, &amp;frac39;</p>
# <p>&amp;frac45;, &amp;frac46;, &amp;frac47;, &amp;frac48;, &amp;frac49;</p>
# <p>&amp;frac56;, &amp;frac57;, &amp;frac58;, &amp;frac59;</p>

I then piped the output to an HTML file to see how the browser renders it.

There is no code in kramdown that converts 1/4, 1/2 and 3/4 to the corresponding fraction character.

Maybe a remnant of legacy code, but a quick repo-wide search on GitHub showed me the following lines:

https://github.com/gettalong/kramdown/blob/0b0a9e072f9a76e59fe2bbafdf343118fb27c3fa/lib/kramdown/converter/latex.rb#L449-L451

gettalong commented 2 years ago

Ah, thanks, now I understand.

To support those other fractions, they need to be added to https://github.com/gettalong/kramdown/blob/master/lib/kramdown/utils/entities.rb#L210-L212.

ashmaroli commented 2 years ago

Ah I see. So it wasn't LaTeX getting involved somehow. Is there a standardized list out there or are the integers assigned to the ENTITIES TABLE arbitrarily?

gettalong commented 2 years ago

See the description of the table - the number is the Unicode code point.

ashmaroli commented 2 years ago

Yes, I read the description comment after I had posted. But left my post unedited in case you had an URL to a standard reference so that future additions could be automated.

gettalong commented 2 years ago

No, sorry, I think I used a table from the HTML spec or Wikipedia.