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

✨ NEW: Add myst_title_to_header configuration #492

Merged
merged 5 commits into from
Jan 9, 2022
Merged

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Jan 6, 2022

This is the "simplest" implementation (3 extra lines!).

Basically, it treats this:

---
title: "A **title**"
---

like this (including parsing nested syntax)

# A **title**

I'm not sure if this would be the correct/expected implementation though

for example, currently

---
title: "A **title**"
---

# Another title

would be treated as

# A **title**

# Another title

but should it instead be treated as

# A **title**

## Another title

(also, on a technical note, the parsing should be a bit smarter, in only allowing inline syntax,
there should probably also be a config to turn it off/on)

@codecov
Copy link

codecov bot commented Jan 6, 2022

Codecov Report

Merging #492 (706e089) into master (74e91e6) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #492      +/-   ##
==========================================
+ Coverage   89.75%   89.81%   +0.06%     
==========================================
  Files          16       16              
  Lines        2069     2072       +3     
==========================================
+ Hits         1857     1861       +4     
+ Misses        212      211       -1     
Flag Coverage Δ
pytests 89.81% <100.00%> (+0.06%) ⬆️

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

Impacted Files Coverage Δ
myst_parser/docutils_renderer.py 91.60% <100.00%> (+0.02%) ⬆️
myst_parser/main.py 88.88% <100.00%> (+0.08%) ⬆️
myst_parser/docutils_.py 80.55% <0.00%> (+0.92%) ⬆️

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 74e91e6...706e089. Read the comment docs.

@chrisjsewell chrisjsewell changed the title PoP Set title in front-matter PoP: Set title in front-matter Jan 6, 2022
@choldgraf
Copy link
Member

Agree with the implementation + your assessment of where it might be confusing. I think it'd be great if specifying title: also bumped all other headers on the page down one level. However if the implementation is complex, then just this PR as it already stands would be an improvement I think

@chrisjsewell
Copy link
Member Author

I think it would be good to check what the behaviour of e.g. pandoc is on this, then just copy that. If even a little more complex, it should be possible either way

@chrisjsewell
Copy link
Member Author

behaviour of pandoc

See https://pandoc.org/MANUAL.html#metadata-blocks

when the --standalone (-s) option is chosen .. The title in the body appears as an H1 element

test.md

---
title: A **title**
---

# Header
$ pandoc -s test.md
...
<body>
<header id="title-block-header">
<h1 class="title">A <strong>title</strong></h1>
</header>
<h1 id="header">Header</h1>
</body>

i.e. the title is parsed as Markdown, and does not affect subsequent headings

@chrisjsewell chrisjsewell changed the title PoP: Set title in front-matter ✨ NEW: Add myst_title_to_header configuration Jan 9, 2022
@chrisjsewell chrisjsewell marked this pull request as ready for review January 9, 2022 10:20
@chrisjsewell
Copy link
Member Author

Ok good to go, if you agree @choldgraf, @rowanc1

@rowanc1
Copy link
Member

rowanc1 commented Jan 9, 2022

Looks good to me! Good to notice the option for this, and updating the docs!

@chrisjsewell
Copy link
Member Author

Looks good to me! Good to notice the option for this, and updating the docs!

Cheers!

Note, with the recent updates I've made, it would actually be quite easy to set a "header level offset", i.e. to turn every # into ## etc.
But as discussed, this is not the behaviour of pandoc (and thus also quarto) plus, as noted by @choldgraf (executablebooks/meta#615 (comment))

Markdown tends to map # to <h1> and ## to <h2>

which I agree is easy for users to understand.

So I think the current behaviour is correct and no offset is needed

@chrisjsewell chrisjsewell merged commit 574b525 into master Jan 9, 2022
@chrisjsewell chrisjsewell deleted the title-metadata branch January 9, 2022 17:12
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.

3 participants