Skip to content

Commit

Permalink
v0.14.3: fix Jinja compat, style checker improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mDuo13 committed May 27, 2021
1 parent ad03f7f commit 648ac29
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions dactyl/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
logger.addHandler(logging.StreamHandler())
logger.propagate = False

PACKAGE_NAME = "dactyl" # Used for Jinja PackageLoader

PDF_USE_DEFAULT = "__DEFAULT_FILENAME__"
NO_PDF = "__NO_PDF__"
ES_USE_DEFAULT = "__ES_USE_DEFAULT__"
Expand Down
2 changes: 1 addition & 1 deletion dactyl/dactyl_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def setup_html_env(self):
else:
preferred_undefined = jinja2.ChainableUndefined

loaderset = [jinja2.PackageLoader(__name__)]
loaderset = [jinja2.PackageLoader(PACKAGE_NAME)]
if "template_path" in self.config:
loaderset.insert(0, jinja2.FileSystemLoader(self.config["template_path"]))
env = jinja2.Environment(undefined=preferred_undefined,
Expand Down
9 changes: 7 additions & 2 deletions dactyl/dactyl_style_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ def load_spellchecker(self):
def load_words_from_file(self, fhandle):
"""
Read a file or file-like object line by line and add the words
from that file to the built-in dictionary.
from that file to the built-in dictionary. Lines starting with # are
treated as comments and ignored.
"""
new_words = []
for line in fhandle:
word = line.strip().lower()
if word:
if word and word[0] != "#":
new_words.append(word)
if new_words:
self.spell.word_frequency.load_words(new_words)
Expand Down Expand Up @@ -171,6 +172,10 @@ def check_page(self, page, context):
# let's strip any of those out.
[div.unwrap() for div in page.soup.find_all(name="div")]

# Inlined SVG elements can't be formatted the same way, so remove them.
# They won't be spell-checked.
[svg.decompose() for svg in page.soup.find_all(name="svg")]

# Sometimes certain elements don't have whitespace between then, so
# .get_text() will mash words together. Adding ". " makes them register
# as separate sentences, which is probably more accurate for readability.
Expand Down
4 changes: 2 additions & 2 deletions dactyl/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def setup_jinja_env(self, template_path=None):
"""Sets up the environment used to inject OpenAPI data into Markdown
templates"""
if template_path is None:
loader = jinja2.PackageLoader(__name__)
loader = jinja2.PackageLoader(PACKAGE_NAME)
else:
logger.debug("OpenAPI spec: preferring templates from %s"%template_path)
loader = jinja2.ChoiceLoader([
jinja2.FileSystemLoader(template_path),
jinja2.PackageLoader(__name__)
jinja2.PackageLoader(PACKAGE_NAME)
])
self.env = jinja2.Environment(loader=loader, extensions=['jinja2.ext.i18n'])
self.env.lstrip_blocks = True
Expand Down
2 changes: 1 addition & 1 deletion dactyl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.14.2'
__version__ = '0.14.3'
8 changes: 8 additions & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v0.14.3 Release Notes

This release adds compatibility with Jinja 3.x and includes two minor improvements to the style checker:

- No longer attempts to check inlined SVG elements. (This caused false reports of misspelled words when the SVG contained text elements without whitespace between them.)
- Spelling file can now contain comments starting with `#`. (Only lines _starting_ with `#` are treated as comments.)


# v0.14.2 Release Notes

This release fixes a couple bugs in the built-in templates when using virtual pages with a `prefix` value. It also changes to use the `prefix` value inherited at the page level so that individual pages can overwrite the value if necessary. (A 404 page, for example, might want to use a separate prefix since it may be used at different paths.)
Expand Down

0 comments on commit 648ac29

Please sign in to comment.