clbarnes / asciidoc-named-char-refs Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hi, I followed your comment from asciidoctor/asciidoctor-pdf#969
I too struggle to see why the PDF output cannot handle XHTML and HTML5 character entities. If it does for HTML output it is confounding that it does not for PDF. The XML argument against it is dubious as argued by the many commentators in the thread; especially the obvious one, i.e., that "pound" is a lot easier to read than "#163" and asciidoc touts its readability.
After some hair pulling, I found this seems to be an alternative solution:
In asciidoctor.rb under INTRINSIC_ATTRIBUTES you can add all of the entities you like, e.g.:
'iexcl' => '¡',
'cent' => '¢',
'pound' => '£',
'curren' => '¤',
I have put the entire XHTML set in there and PDF output was mostly fine (the font inadequacies aside). The only thing that failed was case insensitivity, so Agrave and agrave both rendered as the lowercase version. I did not really understand that because, although I know almost nothing about Ruby, I read that its hashes are case sensitive, which I tested interactively...that was confusing. However, just changing the one line in substitutors.rb from elsif doc_attrs.key?(key = $2.downcase)
to elsif doc_attrs.key?(key = $2)
resolves that (without any obvious side effects that I have seen so far anyway).
The net result is that {iexcl}
, {cent}
, {Agrave}
and {agrave}
, etc., work for both HTML and PDF outputs (the only two I tried).
Example output showing these in the last column
examplePage.pdf
And an example line from the input .asciidoc file:
|\Ù |Ù |\Ù |Ù |U+000D9 |latin capital letter U with grave|{Ugrave}ΒΆ
Currently, enclosing underscores leads to more characters for names which use capitals for distinguishing words (e.g. CapitalDifferentialD -> _C_apital_D_ifferential_D_
), and require escaping when the first and last letters are both capitalised.
The alternative would be to prepend an underscore to any letter which should be capitalised, which may not require escaping, requires fewer keypresses for the example above, but feels less asciidoc-y, and is worse for names like ETH
(_ETH_
vs _E_T_H
).
Lastly, might including the convenient lower-case alternative (e.g. capitaldifferentiald
) possibly threaten forwards-compatibility, if W3C eventually release a new spec where those all-lower names mean some other unicode character?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.