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

Fix indented code block detection and fenced code block categorization #167

Merged
merged 2 commits into from
Mar 10, 2021

Conversation

zhimsel
Copy link
Contributor

@zhimsel zhimsel commented Jul 17, 2020

Please see individual commit messages for more detailed notes.

Happy to address any feedback and RFCs.

Closes #81
Closes #164
Closes #94 (possibly)
Closes #140

@j-hui
Copy link

j-hui commented Mar 8, 2021

While this doesn't explicitly state that a blank line before the code
block is required, in practical testing, it is. As such, I've included
the requirement of a blank line preceeding the indent to match the
region start.

I'm not sure this is always the case. One can leave blank lines between entries in a list, and one may also have multi-paragraph list items. For instance, in this 4-space indented list:

-   Parent paragraph 1

    Parent paragraph 2*

    -   Child paragraph 1

        Child paragraph 2*

            Child code block*

    Parent 1 paragraph 3*

        Parent code block*

I used * to mark all lines that follow a blank line and start with 4 spaces followed by a non-list marker.
The above code is rendered like this:

  • Parent paragraph 1

    Parent paragraph 2*

    • Child paragraph 1

      Child paragraph 2*

      Child code block*
      

    Parent 1 paragraph 3*

    Parent code block*
    

The same is true when you consider 2-space indented lists:

- Parent paragraph 1

  Parent paragraph 2

  - Child paragraph 1

    Child paragraph 2*

        Child code block*

  Parent 1 paragraph 3

      Parent code block*

Rendered like this:

  • Parent paragraph 1

    Parent paragraph 2

    • Child paragraph 1

      Child paragraph 2*

      Child code block*
      

    Parent 1 paragraph 3

    Parent code block*
    

@tpope
Copy link
Owner

tpope commented Mar 10, 2021

@j-hui if I understand you correctly, you are pointing out that fix misses some cases, and not that it breaks anything that wasn't automatically broken. If so, this is helpful to know, but not a deal breaker for merging.

On that I note, I am especially loathe to merge any vim-markdown PR without fully vetting it, because the potential for regressions is so damn high, but given that this is literally a one line change, I feel confident I fully understand it and am willing to merge. @zhimsel Can you ditch the "last changed at" update? I only update that line when submitting upstream to appease Bram. Changing it in every commit makes commands like git revert a nightmare to use.

@j-hui
Copy link

j-hui commented Mar 10, 2021

@tpope yeah, I don't think this will break anything not alrready broken, i.e., it won't highlight anything not already highlighted as a code block.

@zhimsel
Copy link
Contributor Author

zhimsel commented Mar 10, 2021

Can you ditch the "last changed at" update?

Sure thing!

I only update that line when submitting upstream to appease Bram. Changing it in every commit makes commands like git revert a nightmare to use.

Ha, understandable.

Prior to this commit, _any_ line that started with at least 4 spaces or
a tab would be considered a code block.

For example, the third level of a 2-space-indented list would be
highlighted as code, not as list items.

Note: this conforms to the original Markdown spec:
> To produce a code block in Markdown, simply indent every line of the
> block by at least 4 spaces or 1 tab.
> A code block continues until it reaches a line that is not indented
> (or the end of the article).

While this doesn't explicitly state that a blank line _before_ the code
block is required, in practical testing, it is. As such, I've included
the requirement of a blank line preceeding the indent to match the
region start.

Any line not indented by at least 4 spaces will end the region.

Closes tpope#81
Closes tpope#164
Closes tpope#94 (possibly)
Closes tpope#140
Given that there are two separate syntax groups for code and code
blocks, it makes sense to have the triple-backtick/tilde fenced code
blocks be labeled as such.
@tpope tpope merged commit 65cb65a into tpope:master Mar 10, 2021
zhimsel added a commit to zhimsel/dotfiles that referenced this pull request Mar 19, 2021
The custom syntax file is no longer needed, now that
tpope/vim-markdown#167 has been merged. Until
neovim/vim update their builtin syntax files against this, the plugin
needs to be sourced directly.
@zhimsel zhimsel deleted the indented-code-block-fixes branch April 6, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants