Skip to content

Commit

Permalink
docs: Add notes and overview
Browse files Browse the repository at this point in the history
  • Loading branch information
attakei committed Oct 30, 2024
1 parent a52de67 commit 632220b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ atsphinx-linebreak

Enable line-break for everywhere.

Overview
========

This is Sphinx-extension to inject extra node into line-break of source (LF) when it build.
You can write source likely GitHub Flavored Markdown ("Newline" code means as "line-feed of content") by using it.

.. note::

This affects to any sources including reStructuredText.
If you want to change behavior, post PR or issue into GitHub.

Getting started
===============

Expand Down
4 changes: 4 additions & 0 deletions src/atsphinx/linebreak/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class line_break(nodes.Element, nodes.General): # noqa: D101

def visit_line_break(self, node: line_break):
"""Inject br tag (html only)."""
# NOTE: It can change inserting token by configuration.
self.body.append("<br>")


Expand All @@ -22,7 +23,10 @@ def depart_line_break(self, node: line_break):

def inject_line_break(app: Sphinx, doctree: nodes.document):
"""Split text by line-break and inject marker node."""
# NOTE: doctree["source"] has file path of source.
# If it want to change proc by file type, see this.
for text in doctree.findall(nodes.Text):
# NOTE: This may not catch CR+LF (windows) pattern.
if "\n" not in text:
continue
splitted = [(nodes.Text(t), line_break()) for t in text.split("\n")]
Expand Down

0 comments on commit 632220b

Please sign in to comment.