lostenderman / markdown

:notebook_with_decorative_cover: A package for converting and rendering markdown documents in TeX
http://ctan.org/pkg/markdown
LaTeX Project Public License v1.3c
1 stars 0 forks source link

Info strings should show the non-escaped variant #36

Closed lostenderman closed 1 year ago

lostenderman commented 1 year ago

See https://spec.commonmark.org/0.30/#example-143

Witiko commented 1 year ago

The corresponding unit test is testfiles/CommonMark_0.30/fenced_code_blocks/025.test:

%   ---RESULT--- "example": 143,
%   
%   <pre><code class="language-ruby">def foo(x)
%     return 3
%   end
%   </code></pre>
%   
%   ---\RESULT---

<<<
~~~~    ruby startline=3 $%@#$
def foo(x)
  return 3
end
~~~~~~~
>>>
documentBegin
BEGIN fencedCode
- src: ./_markdown_test/bec320a1e3b741ba35aaee15586aa06d.verbatim
- infostring: ruby startline=3 $%@#$
END fencedCode
documentEnd

Here is the result of running git checkout commonmark; cd tests; ./test.sh "testfiles/CommonMark_0.30/fenced_code_blocks/025.test":

Testfile testfiles/CommonMark_0.30/fenced_code_blocks/025.test
  Format templates/plain/
    Template templates/plain/input.tex.m4
      Command pdftex   --shell-escape                  --interaction=nonstopmode  test.tex
*** test-expected.log   2022-12-22 11:55:38.255546587 +0100
--- test-actual.log 2022-12-22 11:55:44.515493283 +0100
***************
*** 1,6 ****
  documentBegin
  BEGIN fencedCode
  - src: ./_markdown_test/bec320a1e3b741ba35aaee15586aa06d.verbatim
! - infostring: ruby startline=3 $%@#$
  END fencedCode
  documentEnd
--- 1,6 ----
  documentBegin
  BEGIN fencedCode
  - src: ./_markdown_test/bec320a1e3b741ba35aaee15586aa06d.verbatim
! - infostring: ruby startline=3 (dollarSign)(percentSign)@(hash)(dollarSign)
  END fencedCode
  documentEnd

This issue seems related to the writer->fencedCode() method, which produces the \markdownRendererInputFencedCode TeX macro. Specifically, we use the writer->string() (or self.escape_typographic_material() under the renaming proposed in #101) method to encode the infostring.

An obvious solution is to replace writer->string() with writer->escape_uri() (or define writer->infostring equal to writer->escape_programmatic_text() under the renaming proposed in #101). However, this makes it impossible to (ab)use infostrings to typeset text such as image labels, see for example Section 1.1.2 and Figure 1 in the TUGboat 42:2 article Markdown 2.10.0: LaTeX themes & snippets, two flavors of comments, and LuaMetaTeX.

Therefore, a better solution would be to change the arity of the \markdownRendererFencedCode macro to 3 and have the writer->fencedCode() use writer->string() for the second parameter and writer->infostring() (after the renaming proposed in #101) for the third parameter. This way, both use cases would be satisfied. In the unit test output (1, 2), we would use the third parameter rather than the second parameter to satisfy the unit test.