mkdocs-include-markdown-plugin 6.2.2__py3-none-any.whl → 7.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@ class PluginConfig(Config): # noqa: D101
17
17
  preserve_includer_indent = MkType(bool, default=True)
18
18
  dedent = MkType(bool, default=False)
19
19
  trailing_newlines = MkType(bool, default=True)
20
- comments = MkType(bool, default=True)
20
+ comments = MkType(bool, default=False)
21
21
  rewrite_relative_urls = MkType(bool, default=True)
22
22
  heading_offset = MkType(int, default=0)
23
23
  start = Optional(MkType(str))
@@ -114,7 +114,7 @@ MARKDOWN_LINK_DEFINITION_REGEX = re.compile(
114
114
  )
115
115
 
116
116
 
117
- def transform_p_by_p_skipping_codeblocks(
117
+ def transform_p_by_p_skipping_codeblocks( # noqa: PLR0912, PLR0915
118
118
  markdown: str,
119
119
  func: Callable[[str], str],
120
120
  ) -> str:
@@ -128,45 +128,80 @@ def transform_p_by_p_skipping_codeblocks(
128
128
  _current_fcodeblock_delimiter = ''
129
129
 
130
130
  # inside indented codeblock
131
- _inside_icodeblock = False
131
+ _maybe_icodeblock_lines: list[str] = []
132
+ _previous_line_was_empty = False
132
133
 
133
134
  lines, current_paragraph = ([], '')
134
135
 
135
136
  def process_current_paragraph() -> None:
136
137
  lines.extend(func(current_paragraph).splitlines(keepends=True))
137
138
 
139
+ # The next implementation takes into account that indented code
140
+ # blocks must be surrounded by newlines as per the CommonMark
141
+ # specification. See https://spec.commonmark.org/0.28/#indented-code-blocks
142
+ #
143
+ # However, note that ambiguities with list items are not handled.
144
+
138
145
  for line in io.StringIO(markdown):
139
- if not _current_fcodeblock_delimiter and not _inside_icodeblock:
146
+ if not _current_fcodeblock_delimiter:
140
147
  lstripped_line = line.lstrip()
141
148
  if (
142
149
  lstripped_line.startswith('```')
143
150
  or lstripped_line.startswith('~~~')
144
151
  ):
145
152
  _current_fcodeblock_delimiter = lstripped_line[:3]
146
- if current_paragraph:
147
- process_current_paragraph()
148
- current_paragraph = ''
153
+ process_current_paragraph()
154
+ current_paragraph = ''
149
155
  lines.append(line)
150
- elif (
151
- line.replace('\t', ' ').replace('\r\n', '\n')
152
- == ' \n'
153
- ):
154
- _inside_icodeblock = True
155
- if current_paragraph:
156
+ elif line.startswith(' '):
157
+ if not lstripped_line or _maybe_icodeblock_lines:
158
+ # maybe enter indented codeblock
159
+ _maybe_icodeblock_lines.append(line)
160
+ else:
161
+ current_paragraph += line
162
+ elif _maybe_icodeblock_lines:
163
+ process_current_paragraph()
164
+ current_paragraph = ''
165
+ if not _previous_line_was_empty:
166
+ # wasn't an indented code block
167
+ for line_ in _maybe_icodeblock_lines:
168
+ current_paragraph += line_
169
+ _maybe_icodeblock_lines = []
170
+ current_paragraph += line
156
171
  process_current_paragraph()
157
172
  current_paragraph = ''
158
- lines.append(line)
173
+ else:
174
+ # exit indented codeblock
175
+ for line_ in _maybe_icodeblock_lines:
176
+ lines.append(line_)
177
+ _maybe_icodeblock_lines = []
178
+ lines.append(line)
159
179
  else:
160
180
  current_paragraph += line
181
+ _previous_line_was_empty = not lstripped_line
161
182
  else:
162
183
  lines.append(line)
163
- if _current_fcodeblock_delimiter:
164
- if line.lstrip().startswith(_current_fcodeblock_delimiter):
165
- _current_fcodeblock_delimiter = ''
166
- elif not line.startswith(' ') and not line.startswith('\t'):
167
- _inside_icodeblock = False
168
-
169
- process_current_paragraph()
184
+ lstripped_line = line.lstrip()
185
+ if lstripped_line.startswith(_current_fcodeblock_delimiter):
186
+ _current_fcodeblock_delimiter = ''
187
+ _previous_line_was_empty = not lstripped_line
188
+
189
+ if _maybe_icodeblock_lines:
190
+ if not _previous_line_was_empty:
191
+ # at EOF
192
+ process_current_paragraph()
193
+ current_paragraph = ''
194
+ for line_ in _maybe_icodeblock_lines:
195
+ current_paragraph += line_
196
+ process_current_paragraph()
197
+ current_paragraph = ''
198
+ else:
199
+ process_current_paragraph()
200
+ current_paragraph = ''
201
+ for line_ in _maybe_icodeblock_lines:
202
+ lines.append(line_)
203
+ else:
204
+ process_current_paragraph()
170
205
 
171
206
  return ''.join(lines)
172
207
 
@@ -180,7 +215,7 @@ def transform_line_by_line_skipping_codeblocks(
180
215
  Skip fenced codeblock lines, where the transformation never is applied.
181
216
 
182
217
  Indented codeblocks are not taken into account because in the practice
183
- this function is never used for transformations on indented lines. See
218
+ this function is only used for transformations of heading prefixes. See
184
219
  the PR https://github.com/mondeja/mkdocs-include-markdown-plugin/pull/95
185
220
  to recover the implementation handling indented codeblocks.
186
221
  """
@@ -269,6 +304,7 @@ def rewrite_relative_urls(
269
304
  functools.partial(found_href, url_group_index=2),
270
305
  paragraph,
271
306
  )
307
+
272
308
  return transform_p_by_p_skipping_codeblocks(
273
309
  markdown,
274
310
  transform,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: mkdocs-include-markdown-plugin
3
- Version: 6.2.2
3
+ Version: 7.0.0
4
4
  Summary: Mkdocs Markdown includer plugin.
5
5
  Project-URL: Source, https://github.com/mondeja/mkdocs-include-markdown-plugin
6
6
  Project-URL: Documentation, https://github.com/mondeja/mkdocs-include-markdown-plugin#documentation
@@ -17,7 +17,6 @@ Classifier: Environment :: Console
17
17
  Classifier: Intended Audience :: Developers
18
18
  Classifier: License :: OSI Approved :: Apache Software License
19
19
  Classifier: Operating System :: OS Independent
20
- Classifier: Programming Language :: Python :: 3.8
21
20
  Classifier: Programming Language :: Python :: 3.9
22
21
  Classifier: Programming Language :: Python :: 3.10
23
22
  Classifier: Programming Language :: Python :: 3.11
@@ -27,7 +26,7 @@ Classifier: Topic :: Documentation
27
26
  Classifier: Topic :: Software Development :: Documentation
28
27
  Classifier: Topic :: Text Processing
29
28
  Classifier: Topic :: Text Processing :: Markup :: Markdown
30
- Requires-Python: >=3.8
29
+ Requires-Python: >=3.9
31
30
  Requires-Dist: mkdocs>=1.4
32
31
  Requires-Dist: wcmatch
33
32
  Provides-Extra: cache
@@ -204,10 +203,10 @@ content to include.
204
203
  are rewritten to work correctly in their new location. Possible values are
205
204
  `true` and `false`.
206
205
  - <a name="include-markdown_comments" href="#include-markdown_comments">#</a>
207
- **comments** (_true_): When this option is enabled (default), the content to
208
- include is wrapped by `<!-- BEGIN INCLUDE -->` and `<!-- END INCLUDE -->`
209
- comments which help to identify that the content has been included. Possible
210
- values are `true` and `false`.
206
+ **comments** (_false_): When this option is enabled, the content to include
207
+ is wrapped by `<!-- BEGIN INCLUDE -->` and `<!-- END INCLUDE -->` comments
208
+ which help to identify that the content has been included. Possible values
209
+ are `true` and `false`.
211
210
  - <a name="include-markdown_heading-offset" href="#include-markdown_heading-offset">#</a>
212
211
  **heading-offset** (0): Increases or decreases the Markdown headings depth
213
212
  by this number. Only supports number sign (`#`) heading syntax. Accepts
@@ -229,7 +228,7 @@ content to include.
229
228
  start='<!--\n\ttable-start\n-->'
230
229
  end='<!--\n\ttable-end\n-->'
231
230
  rewrite-relative-urls=false
232
- comments=false
231
+ comments=true
233
232
  %}
234
233
  ```
235
234
 
@@ -1,15 +1,15 @@
1
1
  mkdocs_include_markdown_plugin/__init__.py,sha256=ByOde15RQSHlZTmkepPSzIt0GzUIv_-GKORFDnxnOmc,193
2
2
  mkdocs_include_markdown_plugin/cache.py,sha256=fFm2kU3ONoE2euo0rHC8DOBmV-ubX6BsfHe9hVFeRf4,2880
3
- mkdocs_include_markdown_plugin/config.py,sha256=CTP5xhdZwPKuee3urDLOjanV93uhHHAL8XZ3L6_2HIE,861
3
+ mkdocs_include_markdown_plugin/config.py,sha256=GezwaOHzZ3eDayweFEEG0b7PuWFIqiBBn-XMXrP0U3Q,862
4
4
  mkdocs_include_markdown_plugin/directive.py,sha256=K0-lnw5AOwwLv0MShGydhhZQrS_07w-sizcQCuivGSY,9313
5
5
  mkdocs_include_markdown_plugin/event.py,sha256=37x21rRdIDsZDkUZjxb-IgxHy1olZ7yxqTxFedPlAFU,24001
6
6
  mkdocs_include_markdown_plugin/files_watcher.py,sha256=hu-63u8syl00mXP59vP_iqD7T1R9iU9JjiZOHDV5fas,298
7
7
  mkdocs_include_markdown_plugin/logger.py,sha256=nl63G4IJSt5mEYHbObuh7BmmowSv-aa1l_v9I257570,230
8
8
  mkdocs_include_markdown_plugin/plugin.py,sha256=PfpU2nrc2jlAtbVg5-c6GiK2GSwkFPEos5zvbGkONOo,3812
9
- mkdocs_include_markdown_plugin/process.py,sha256=3TT0Zkv-IWAloDuuLpcw-SR62lRQyxzDk_K8heFJl58,15669
9
+ mkdocs_include_markdown_plugin/process.py,sha256=DLbq_Alj1_XSKbTxLHl9IRxEO3XBNmavgksJJuwnwlY,17210
10
10
  mkdocs_include_markdown_plugin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- mkdocs_include_markdown_plugin-6.2.2.dist-info/METADATA,sha256=wDrrPZPZ8gpPTNFZTLjHUIirYKnewCwb3AzhOI6WSig,12142
12
- mkdocs_include_markdown_plugin-6.2.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
13
- mkdocs_include_markdown_plugin-6.2.2.dist-info/entry_points.txt,sha256=WEL5m7sw5ZMBwmdOs5S_9mGoZfLCaUDPkDKw7CUk16Q,96
14
- mkdocs_include_markdown_plugin-6.2.2.dist-info/licenses/LICENSE,sha256=OunyKlPxiuvLB3ENbo2nyV-OPndkwzyZ5Gzwei0ofbc,11365
15
- mkdocs_include_markdown_plugin-6.2.2.dist-info/RECORD,,
11
+ mkdocs_include_markdown_plugin-7.0.0.dist-info/METADATA,sha256=h1gJX1qFKDa3dB2kkqz-bE0SWrpVZ5qRIsfhW19mdhQ,12082
12
+ mkdocs_include_markdown_plugin-7.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
13
+ mkdocs_include_markdown_plugin-7.0.0.dist-info/entry_points.txt,sha256=WEL5m7sw5ZMBwmdOs5S_9mGoZfLCaUDPkDKw7CUk16Q,96
14
+ mkdocs_include_markdown_plugin-7.0.0.dist-info/licenses/LICENSE,sha256=OunyKlPxiuvLB3ENbo2nyV-OPndkwzyZ5Gzwei0ofbc,11365
15
+ mkdocs_include_markdown_plugin-7.0.0.dist-info/RECORD,,