yzhang-gh / vscode-markdown

Markdown All in One
https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one
MIT License
2.92k stars 326 forks source link

Support setext headings (underlined with `===` or `---`) in Toggle heading #794

Open theherk opened 4 years ago

theherk commented 4 years ago

What is the problem?

When using C-} to promote the line under cursor to H1 or H2 and C-{ to demote to H1 or H2, # and ## are used. This is not a problem. The problem is that there doesn't seem to be an option to use === and --- in lieu of these.

How can I reproduce it?

Enter "Some Text", then C-}. This will convert to "# Some Text".

Is there any error message in the console?

No.

Suggested Feature

use-fancy-headings

If this feature were enabled the workflow would follow:

enter "Some Text"

Some Text

C-}

Some Text
=========

modify to "Some Different Text"

Some Different Text
=========

C-}, now H2, and modification updates number of ='s or -'s

Some Different Text
-------------------

Is this even possible? If so, I'd be happy to work on it. If it exists already, I'm sorry for the entry.

yzhang-gh commented 4 years ago

Thanks for the feedback.

It is possible. You can have a look at

https://github.com/yzhang-gh/vscode-markdown/blob/8ca0b084d1ede2263d13fb50d03049111358f8b5/src/formatting.ts#L52-L80

Lemmingh commented 4 years ago

If I understand correctly, this request is to add setext heading support to toggleHeadingUp() and toggleHeadingDown()?

yzhang-gh commented 4 years ago

I think so

gavbarnett commented 3 years ago

Seem like this would also be nice as an autocompletion feature.

When typing a setex heading underline it should offer to complete based on the length of the heading above.

After typing a valid setex heading underline offer to complete to heading length by repeating what ever valid underline has been used be that (-)------- , (=)=====, (- )- - - - - -, (-- )-- -- --, etc.

yzhang-gh commented 3 years ago

Sounds better

tom-newhall commented 11 months ago

HI, was syntax highlighting for sextet headings ever implemented?

If not, is there a way to implement them

Thanks

yzhang-gh commented 11 months ago

@tom-newhall The basic Markdown syntax highlighting is provided by VS Code itself. Please see

https://github.com/microsoft/vscode/blob/main/extensions/markdown-basics/syntaxes/markdown.tmLanguage.json

tom-newhall commented 11 months ago

Thanks so much for getting back to me. Sorry my question was not very detailed. Right now, the default behavior is that only the === and --- lines are highlighted for setext headings. I would ideally like both the text on the line before and the === / --- to be highlighted. Is this possible, i.e. with begin and end?

Also, if I wanted to modify the markdown.tmLanguage.json file that you pointed to earlier, where would I find that?

Thanks in advance

yzhang-gh commented 11 months ago

You can see the regular expressions at https://github.com/microsoft/vscode/blob/55d7566112ae7de85a6ff75d85374aad95d1cea9/extensions/markdown-basics/syntaxes/markdown.tmLanguage.json#L2265-L2276

However, the tmlanguage isn't that easy to use. I suggest using an extension (e.g. Highlight) to do this.