Skip to content

Commit 31e38f7

Browse files
committed
docs: describe Document's constructor (#64)
Describing what it does and how end-of-lines are treated.
1 parent 52737ce commit 31e38f7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

mistletoe/block_token.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import re
66
from itertools import zip_longest
7+
from typing import Iterable, Union
78
import mistletoe.block_tokenizer as tokenizer
89
from mistletoe import token, span_token
910
from mistletoe.core_tokens import (
@@ -136,7 +137,19 @@ class Document(BlockToken):
136137
footnotes (dictionary): link reference definitions.
137138
"""
138139

139-
def __init__(self, lines):
140+
def __init__(self, lines: Union[str, Iterable[str]]):
141+
"""
142+
Instantiates this token and its content by parsing the input lines.
143+
144+
Args:
145+
lines: input markdown to be tokenized. If a string is provided,
146+
it will be split into lines.
147+
148+
CAUTION: If the input lines end with Windows line endings (``\\r\\n``),
149+
the parsing process will not work correctly. For performance reasons,
150+
clients need to normalize such line endings themselves, before passing
151+
them to this function, e.g. by calling ``lines.replace('\\r', '')``.
152+
"""
140153
if isinstance(lines, str):
141154
lines = lines.splitlines(keepends=True)
142155
lines = [line if line.endswith('\n') else '{}\n'.format(line) for line in lines]

0 commit comments

Comments
 (0)