diff --git a/src/pygments_markdown_lexer/lexer.py b/src/pygments_markdown_lexer/lexer.py index 33a8079..a4a468b 100644 --- a/src/pygments_markdown_lexer/lexer.py +++ b/src/pygments_markdown_lexer/lexer.py @@ -35,6 +35,7 @@ class Markdown(object): Markup = Keyword Heading = Generic.Heading SubHeading = Generic.Heading + InlineCode = Token.Literal.String.Backtick CodeBlock = Comment.Preproc HtmlSingle = Comment.Single HtmlBlock = Comment.Preproc @@ -112,7 +113,8 @@ class MarkdownLexer(RegexLexer): (r'&', Text), # Inline code - (r'``?', Markdown.Markup, state('literal')), + (r'(`+) ?(.*?) ?(\1)', + bygroups(Markdown.Markup, Markdown.InlineCode, Markdown.Markup)), # Emphasis (r'_?_[ \n]', Text), # whitespace escape @@ -141,10 +143,6 @@ class MarkdownLexer(RegexLexer): (r'[a-zA-Z0-9]+', Text), # optimize normal words a little (r'.', Text), # default fallback ], - state('literal'): [ - (r'[^`]+', String.Backtick), - (r'(?]+>\n', Markdown.HtmlBlock, state('#pop')), (r'.*\n', Markdown.HtmlBlock), # slurp boring text diff --git a/src/tests/test_lexer.py b/src/tests/test_lexer.py index f0074d8..47f8cda 100644 --- a/src/tests/test_lexer.py +++ b/src/tests/test_lexer.py @@ -229,3 +229,11 @@ def test_lists_and_blockquotes(): (Markdown.Markup, '\t' + lead + ' '), (Text, 'Lorem ipsum.\n'), ) + +def test_inline_code(): + check( + (Markdown.Markup, r'``'), + (Markdown.InlineCode, 'There is a literal backtick (`) here.'), + (Markdown.Markup, r'``'), + (Text, '\n'), + )