diff --git a/Makefile b/Makefile index 523ae21..0f71ee0 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ test-diff: @$(SPHINX_BUILD) -M markdown "$(SOURCE_DIR)" "$(BUILD_DIR)/overrides" $(SPHINX_OPTS) $(O) -a \ -D markdown_http_base="https://localhost" -D markdown_uri_doc_suffix=".html" \ -D markdown_docinfo=1 -D markdown_anchor_sections=1 -D markdown_anchor_signatures=1 \ - -D autodoc_typehints=signature -D markdown_bullet=- + -D autodoc_typehints=signature -D markdown_bullet=- -D markdown_flavor=github @# Copy just the files for verification @cp "$(BUILD_DIR)/overrides/markdown/auto-summery.md" "$(BUILD_DIR)/markdown/overrides-auto-summery.md" diff --git a/README.md b/README.md index 90ff22b..7f8fab2 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ You can add the following configurations to your `conf.py` file: * `markdown_uri_doc_suffix`: If set, all references will link to documents with this suffix. * `markdown_file_suffix`: Sets the file extension for generated markdown files (default: `.md`). * `markdown_bullet`: Sets the bullet marker. +* `markdown_flavor`: If set to `github`, output will suit GitHub's flavor of Markdown. For example, if your `conf.py` file have the following configuration: diff --git a/sphinx_markdown_builder/__init__.py b/sphinx_markdown_builder/__init__.py index a10c38f..2a5261e 100644 --- a/sphinx_markdown_builder/__init__.py +++ b/sphinx_markdown_builder/__init__.py @@ -20,6 +20,7 @@ def setup(app) -> ExtensionMetadata: app.add_config_value("markdown_anchor_signatures", False, "html", bool) app.add_config_value("markdown_docinfo", False, "html", bool) app.add_config_value("markdown_bullet", "*", "html", str) + app.add_config_value("markdown_flavor", "", "html", str) return { "version": __version__, diff --git a/sphinx_markdown_builder/translator.py b/sphinx_markdown_builder/translator.py index 2356ac1..127fc5e 100644 --- a/sphinx_markdown_builder/translator.py +++ b/sphinx_markdown_builder/translator.py @@ -345,6 +345,9 @@ def visit_image(self, node): # noinspection PyPep8Naming def visit_Text(self, node): # pylint: disable=invalid-name text = node.astext().replace("\r", "") + # Replace line breaks with spaces to create single-line paragraphs + if self.config.markdown_flavor == "github": + text = text.replace("\n", " ") if self.status.escape_text: text = escape_markdown_chars(text) self.add(text) diff --git a/tests/expected/overrides-auto-module.md b/tests/expected/overrides-auto-module.md index 960ec21..a22b8ed 100644 --- a/tests/expected/overrides-auto-module.md +++ b/tests/expected/overrides-auto-module.md @@ -39,8 +39,7 @@ Deprecated since version 3.1: Use `other()` instead. ### func1(param1: [int](https://docs.python.org/3/library/functions.html#int)) → [int](https://docs.python.org/3/library/functions.html#int) -This is a function with a single parameter. -Thanks to github.com/remiconnesson. +This is a function with a single parameter. Thanks to github.com/remiconnesson. * **Parameters:** **param1** – This is a single parameter. diff --git a/tests/expected/overrides-auto-summery.md b/tests/expected/overrides-auto-summery.md index eee5091..dc61a49 100644 --- a/tests/expected/overrides-auto-summery.md +++ b/tests/expected/overrides-auto-summery.md @@ -3,10 +3,7 @@ - + diff --git a/tests/test_builder.py b/tests/test_builder.py index 588163f..7fef9ea 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -34,6 +34,8 @@ "markdown_bullet=-", "-D", "markdown_file_suffix=.html.md", + "-D", + "markdown_flavor=github", "-j", "8", ],