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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 FIX: front-matter rendering with docutils #477

Merged
merged 8 commits into from Dec 28, 2021

Conversation

chrisjsewell
Copy link
Member

For the docutils base HTML writer, it is expected that field_body contain block elements (e.g. paragraph) as children, rather than Text, meaning this file:

---
a: 1
---

leads to:

$ myst-docutils-html test.txt --traceback 
Traceback (most recent call last):
  File "/path/bin/myst-docutils-html", line 33, in <module>
    sys.exit(load_entry_point('myst-parser', 'console_scripts', 'myst-docutils-html')())
  File "/path/lib/python3.7/site-packages/myst_parser/docutils_.py", line 248, in cli_html
    _run_cli("html", "(X)HTML documents", argv)
  File "/path/lib/python3.7/site-packages/myst_parser/docutils_.py", line 242, in _run_cli
    argv=argv,
  File "/path/lib/python3.7/site-packages/docutils/core.py", line 355, in publish_cmdline
    config_section=config_section, enable_exit_status=enable_exit_status)
  File "/path/lib/python3.7/site-packages/docutils/core.py", line 220, in publish
    output = self.writer.write(self.document, self.destination)
  File "/path/lib/python3.7/site-packages/docutils/writers/__init__.py", line 78, in write
    self.translate()
  File "/path/lib/python3.7/site-packages/docutils/writers/_html_base.py", line 80, in translate
    self.document.walkabout(visitor)
  File "/path/lib/python3.7/site-packages/docutils/nodes.py", line 227, in walkabout
    if child.walkabout(visitor):
  File "/path/lib/python3.7/site-packages/docutils/nodes.py", line 227, in walkabout
    if child.walkabout(visitor):
  File "/path/lib/python3.7/site-packages/docutils/nodes.py", line 227, in walkabout
    if child.walkabout(visitor):
  File "/path/lib/python3.7/site-packages/docutils/nodes.py", line 219, in walkabout
    visitor.dispatch_visit(self)
  File "/path/lib/python3.7/site-packages/docutils/nodes.py", line 2021, in dispatch_visit
    return method(node)
  File "/path/lib/python3.7/site-packages/docutils/writers/html4css1/__init__.py", line 414, in visit_field_body
    self.set_class_on_child(node, 'first', 0)
  File "/path/lib/python3.7/site-packages/docutils/writers/_html_base.py", line 407, in set_class_on_child
    child['classes'].append(class_)
TypeError: string indices must be integers

@codecov
Copy link

codecov bot commented Dec 28, 2021

Codecov Report

Merging #477 (56214b0) into master (fb3e8e1) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #477      +/-   ##
==========================================
+ Coverage   90.18%   90.19%   +0.01%     
==========================================
  Files          16       16              
  Lines        2027     2030       +3     
==========================================
+ Hits         1828     1831       +3     
  Misses        199      199              
Flag Coverage 螖
pytests 90.19% <100.00%> (+0.01%) 猬嗭笍

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage 螖
myst_parser/docutils_renderer.py 92.66% <100.00%> (+0.03%) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update fb3e8e1...56214b0. Read the comment docs.

@chrisjsewell
Copy link
Member Author

chrisjsewell commented Dec 28, 2021

TODO: split fixtures test into docutils/sphinx (and make clear they test AST before transforms), add test for docutils, add source/line to elements

@chrisjsewell chrisjsewell marked this pull request as ready for review December 28, 2021 19:27
@chrisjsewell chrisjsewell merged commit 6c44075 into master Dec 28, 2021
@chrisjsewell chrisjsewell deleted the fix-front-matter branch December 28, 2021 19:29
chrisjsewell added a commit that referenced this pull request Dec 29, 2021
After #477, I noted that the `SmartQuote` transform was being applied to  the front-matter values,
before they were extracted to the document metadata.
Therefore, we now add them as a `literal` to stop this happening.
chrisjsewell added a commit that referenced this pull request Dec 29, 2021
After PR #477, I noted that the `SmartQuote` transform was being applied to  the front-matter values,
before they were extracted to the document metadata (see also issue #479).
Therefore, we now add them as a `literal` to stop this happening.
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

Successfully merging this pull request may close these issues.

None yet

1 participant