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

Add yaml metadata parsing #91

Merged
merged 1 commit into from
Feb 10, 2016

Conversation

cosmicexplorer
Copy link
Contributor

Also add testing and allow multiple pandoc metadata blocks. Fix #66.

(defun markdown-match-generic-metadata (regexp last)
(defun markdown-get-match-boundaries (start-header end-header last &optional pos)
(save-excursion
(goto-char (if pos pos (point-min)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about (or pos (point-min)) like other parts ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, not sure what I was thinking.

@syohex
Copy link
Collaborator

syohex commented Feb 9, 2016

Thanks for great work. I put some comments, please check them.

@syohex
Copy link
Collaborator

syohex commented Feb 10, 2016

Looks good. Could you squash commits ?

@cosmicexplorer
Copy link
Contributor Author

Done.

@syohex
Copy link
Collaborator

syohex commented Feb 10, 2016

And please remove following lines from commit messages, they makes no sense.

  • Add defvar for markdown-search-until-condition
  • Update with comments from @syohex

Also allow multiple pandoc metadata, with tests. Fix jrblevin#66.
@cosmicexplorer
Copy link
Contributor Author

Fixed.

syohex added a commit that referenced this pull request Feb 10, 2016
@syohex syohex merged commit b1484b6 into jrblevin:master Feb 10, 2016
@syohex
Copy link
Collaborator

syohex commented Feb 10, 2016

Thanks 👍

@jrblevin
Copy link
Owner

Thanks for this patch. I only noticed one potential issue: YAML blocks inside fenced code blocks should be ignored:

```
---
title: foo
author: bar
---
```

You can use markdown-code-block-at-pos or markdown-code-block-at-point in the propertize function to skip code blocks.

@jrblevin
Copy link
Owner

Regarding my comment above about YAML in code blocks, I appended the test case and marked it with :expected-result :failed for now. See commit 90f3f59. I took a shot at fixing it, but it's more complicated than I thought. I think we also need to check for code blocks in markdown-get-match-boundaries, because of the separate matching functions.

@cosmicexplorer
Copy link
Contributor Author

I'll take a look at these tomorrow. I think I can speed up the metadata block matching by propertizing metadata block start and end boundaries (the ---\n lines) and searching for characters with that property. We can then search for code block boundaries as well, using the same trick.

With respect to the if statements, I wanted to allow for local binding of the pandoc style; if you want to remove the if statements, I can factor that out into a separate function.

@vyp
Copy link

vyp commented Feb 12, 2016

Thank you @cosmicexplorer for this! 👍

@cosmicexplorer
Copy link
Contributor Author

Thinking about it a bit more, metadata would be invalid inside any other "block"-level construct, such as gfm code blocks or tilde blocks; I think that's it? All the other block constructs have some required characters at the beginning of each line. I think what would probably work would be to propertize all three "border" types (gfm blocks, pandoc tilde blocks, yaml metadata blocks) at once in a single pass, then figure out the appropriate context for any text enclosed within them by finding which if any characters with the syntax property for start/end blocks of those three block types are closest to the characters to propertize.

So basically, if our text is like:

... (some stuff without ~~~, ```, or ---)
`` ` (propertized as gfm-codeblock-begin by first block-construct pass)
--- (not propertized because already within block construct, but with markdown-inline-code-face)
key: value (look for enclosing block propertized text; found gfm-codeblock, so no propertizing/highlighting)
--- (not propertized)
`` ` (gfm-codeblock-end)

I'll try to do this, it seems not too hard.

cosmicexplorer pushed a commit to cosmicexplorer/markdown-mode that referenced this pull request Feb 14, 2016
Improve on jrblevin#91 by increasing speed of matching block constructs, and
allow them to be nested within each other, by matching all of them in a
single pass.

- Ensure font locking of block constructs is predicated solely on text
properties.
- Add "language" field to tilde fence opening regexp.
- Make `test-markdown-font-lock/pandoc-yaml-metadata` pass.
cosmicexplorer pushed a commit to cosmicexplorer/markdown-mode that referenced this pull request Feb 16, 2016
Improve on jrblevin#91 by increasing speed of matching block constructs, and
allow them to be nested within each other, by matching all of them in a
single pass.

- Ensure font locking of block constructs is predicated solely on text
properties.
- Add "language" field to tilde fence opening regexp.
- Make `test-markdown-font-lock/pandoc-yaml-metadata` pass.
- Add `markdown-font-lock-extend-region-function` and rework
`markdown-syntax-propertize-extend-region` to stretch
repropertization/refontification to all of a code block.
- Add test cases for fenced block conditions.
cosmicexplorer pushed a commit to cosmicexplorer/markdown-mode that referenced this pull request Feb 16, 2016
Improve on jrblevin#91 by increasing speed of matching block constructs, and
allow them to be nested within each other, by matching all of them in a
single pass.

- Ensure font locking of block constructs is predicated solely on text
properties.
- Add "language" field to tilde fence opening regexp.
- Make `test-markdown-font-lock/pandoc-yaml-metadata` pass.
- Add `markdown-font-lock-extend-region-function` and rework
`markdown-syntax-propertize-extend-region` to stretch
repropertization/refontification to all of a code block.
- Add test cases for fenced block conditions.
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

4 participants