Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions markdown_it/rules_block/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ def reference(state: StateBlock, startLine, _endLine, silent):

state.line = startLine + lines + 1

# note, this is not part of markdown-it JS, but is useful for renderers
if state.md.options.get("inline_definitions", False):
token = state.push("definition", "", 0)
token.meta = {
"id": label,
"title": title,
"url": href,
"label": string[1:labelEnd],
}
token.map = [startLine, state.line]

if label not in state.env["references"]:
state.env["references"][label] = {
"title": title,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_port/test_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ def test_store_labels(data_regression):
src = "[a]\n\n![a]\n\n[a]: ijk"
tokens = md.parse(src)
data_regression.check([token.as_dict() for token in tokens])


def test_inline_definitions(data_regression):
md = MarkdownIt()
md.options["inline_definitions"] = True
src = '[a]: url "title"\n- [a]: url "title"'
tokens = md.parse(src)
data_regression.check([token.as_dict() for token in tokens])
94 changes: 94 additions & 0 deletions tests/test_port/test_references/test_inline_definitions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
- attrs: null
block: true
children: null
content: ''
hidden: false
info: ''
level: 0
map:
- 0
- 1
markup: ''
meta:
id: A
label: a
title: title
url: url
nesting: 0
tag: ''
type: definition
- attrs: null
block: true
children: null
content: ''
hidden: false
info: ''
level: 0
map:
- 1
- 2
markup: '-'
meta: {}
nesting: 1
tag: ul
type: bullet_list_open
- attrs: null
block: true
children: null
content: ''
hidden: false
info: ''
level: 1
map:
- 1
- 2
markup: '-'
meta: {}
nesting: 1
tag: li
type: list_item_open
- attrs: null
block: true
children: null
content: ''
hidden: false
info: ''
level: 2
map:
- 1
- 2
markup: ''
meta:
id: A
label: a
title: title
url: url
nesting: 0
tag: ''
type: definition
- attrs: null
block: true
children: null
content: ''
hidden: false
info: ''
level: 1
map: null
markup: '-'
meta: {}
nesting: -1
tag: li
type: list_item_close
- attrs: null
block: true
children: null
content: ''
hidden: false
info: ''
level: 0
map: null
markup: '-'
meta: {}
nesting: -1
tag: ul
type: bullet_list_close
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ usedevelop = true
extras =
linkify
testing
commands = pytest tests/ {posargs}
commands = pytest {posargs:tests/}

[testenv:py{36,37,38,39,310}-plugins]
extras = testing
Expand Down