0

I use markdown-it like so

const markdown = require("markdown-it")("default", {
    html: true,
    linkify: true,
    typographer: true
});
const htmlText = markdown.render(textFileContent);

and it works fine with until I do

#Big title

##Title

#Small title

which get wrapped into <p> instead of <h1> <h2> . Note this works with Github. etc

but this works

Big title
---------

Title
=======

I cannot change the markdown. User expect it to be parsed like it does in GitHub and stackoverflow.

2
  • Do with an alternative syntax, you probably need an alternative parser. Commented Dec 16, 2016 at 12:50
  • What parser do you recommend ? Commented Dec 16, 2016 at 13:13

1 Answer 1

1

Like all implementations that follow the CommonMark spec, markdown-it requires a space between ATX-style header indicators and heading text.

This should work:

# Big title

## Title

# Small title

I believe that this also makes the source easier to read, which is one of Markdown's fundamental goals:

The overriding design goal for Markdown’s formatting syntax is to make it as readable as possible. The idea is that a Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions.

However, if you wish to support headers without a space you can use the markdown-it-lazy-headers plugin:

markdown-it-lazy-headers is a plugin for markdown-it that relaxes the syntax of ATX headers so that you don't have to follow the opening sequence of # characters by a space.

Sign up to request clarification or add additional context in comments.

1 Comment

@WalleCyril, there is a plugin you can use to support ATX headers without a space. See my updated answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.