Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limited rendering of fraction entities #769

Open
ashmaroli opened this issue Sep 30, 2022 · 7 comments
Open

Limited rendering of fraction entities #769

ashmaroli opened this issue Sep 30, 2022 · 7 comments
Assignees

Comments

@ashmaroli
Copy link
Contributor

ashmaroli commented Sep 30, 2022

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
Copy link
Owner

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?

@gettalong gettalong self-assigned this Sep 30, 2022
@ashmaroli
Copy link
Contributor Author

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:

189 => ['$\frac{1}{2}$'],
188 => ['$\frac{1}{4}$'],
190 => ['$\frac{3}{4}'],

@gettalong
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

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

@ashmaroli
Copy link
Contributor Author

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants