This repository has been archived by the owner on Mar 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
dev: update dependencies #30
Open
p1tt1
wants to merge
3
commits into
benwr:master
Choose a base branch
from
p1tt1:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,15 +37,18 @@ | |
```yaml | ||
recur_dir: ~/ankdown_cards | ||
pkg_arg: ~/ankdown_cards.apkg | ||
math_mode: dollars | ||
misaka_renderer: HighlighterRenderer, | ||
misaka_extensions: [fenced-code, math, tables], | ||
card_model_name: CustomModelName | ||
card_model_css: ".card {font-family: 'Crimson Pro', 'Crimson Text', 'Cardo', 'Times', 'serif'; text-align: left; color: black; background-color: white;}" | ||
dollar: True | ||
|
||
``` | ||
|
||
A configuration can also be passed as a string: `"{dollar: True, card_model_name: CustomModelName, card_model_css: \".card {text-align: left;}\"}"` | ||
A configuration can also be passed as a string: `"{card_model_name: CustomModelName, card_model_css: \".card {text-align: left;}\"}"` | ||
|
||
Usage: | ||
ankdown.py [-r DIR] [-p PACKAGENAME] [--highlight] [--config=CONFIG_STRING] [--configFile=CONFIG_FILE_PATH] | ||
ankdown.py [-r DIR] [-p PACKAGENAME] [--config=CONFIG_STRING] [--configFile=CONFIG_FILE_PATH] | ||
|
||
Options: | ||
-h --help Show this help message | ||
|
@@ -55,8 +58,6 @@ | |
|
||
-p PACKAGE Instead of a .txt file, produce a .apkg file. recommended. | ||
|
||
--highlight Enable syntax highlighting for code | ||
|
||
--config=CONFIG_STRING ankdown configuration as YAML string | ||
|
||
--configFile=CONFIG_FILE_PATH path to ankdown configuration as YAML file | ||
|
@@ -96,10 +97,6 @@ def blockcode(self, text, lang): | |
return '\n<pre><code>{}</code></pre>\n'.format( | ||
h.escape_html(text.strip())) | ||
|
||
|
||
renderer = HighlighterRenderer() | ||
highlight_markdown = misaka.Markdown(renderer, extensions=("fenced-code", "math")) | ||
|
||
VERSION = "0.7.1" | ||
|
||
# Anki 2.1 has mathjax built in, but ankidroid and other clients don't. | ||
|
@@ -133,8 +130,9 @@ def blockcode(self, text, lang): | |
CONFIG = { | ||
'pkg_arg': 'AnkdownPkg.apkg', | ||
'recur_dir': '.', | ||
'dollar': False, | ||
'highlight': False, | ||
'math_mode': 'brackets', | ||
'misaka_renderer': 'HtmlRenderer', | ||
'misaka_extensions': ['fenced-code', 'math'], | ||
'card_model_name': 'Ankdown Model 2', | ||
'card_model_css': """ | ||
.card { | ||
|
@@ -261,24 +259,31 @@ def __getitem__(self, deckname): | |
def field_to_html(field): | ||
"""Need to extract the math in brackets so that it doesn't get markdowned. | ||
If math is separated with dollar sign it is converted to brackets.""" | ||
if CONFIG['dollar']: | ||
if CONFIG['math_mode'] is 'dollars': | ||
for (sep, (op, cl)) in [("$$", (r"\\[", r"\\]")), ("$", (r"\\(", r"\\)"))]: | ||
escaped_sep = sep.replace(r"$", r"\$") | ||
# ignore escaped dollar signs when splitting the field | ||
field = re.split(r"(?<!\\){}".format(escaped_sep), field) | ||
# add op(en) and cl(osing) brackets to every second element of the list | ||
field[1::2] = [op + e + cl for e in field[1::2]] | ||
field = "".join(field) | ||
# | ||
# CONFIG['math_mode'] is 'brackets' OR fallback case | ||
# | ||
else: | ||
for bracket in ["(", ")", "[", "]"]: | ||
field = field.replace(r"\{}".format(bracket), r"\\{}".format(bracket)) | ||
# backslashes, man. | ||
|
||
if CONFIG['highlight']: | ||
return highlight_markdown(field) | ||
|
||
|
||
return misaka.html(field, extensions=("fenced-code", "math")) | ||
if CONFIG['misaka_renderer'] is 'HighlighterRenderer': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also should be |
||
renderer = HighlighterRenderer() | ||
# | ||
# CONFIG['misakq_renderer'] is 'HtmlRenderer' OR fallback case | ||
# | ||
else: | ||
renderer = misaka.HtmlRenderer() | ||
|
||
return misaka.Markdown(renderer, CONFIG['misaka_extensions'])(field) | ||
|
||
|
||
def compile_field(field_lines, is_markdown): | ||
|
@@ -358,16 +363,13 @@ def apply_arguments(arguments): | |
CONFIG['pkg_arg'] = arguments.get('-p') | ||
if arguments.get('-r') is not None: | ||
CONFIG['recur_dir'] = arguments.get('-r') | ||
if arguments.get('--highlight'): | ||
CONFIG['highlight'] = True | ||
|
||
|
||
def apply_highlight_css(): | ||
global CONFIG | ||
css_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'highlight.css') | ||
with open(css_file_path) as css_file: | ||
CONFIG['card_model_css'] += css_file.read().replace('\n', '') | ||
|
||
# | ||
# add highlight css rules | ||
# | ||
if CONFIG['misaka_renderer'] is 'HighlighterRenderer': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also should be |
||
highlight_css_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'highlight.css') | ||
with open(highlight_css_file_path) as highlight_css_file: | ||
CONFIG['card_model_css'] += highlight_css_file.read().replace('\n', '') | ||
|
||
def main(): | ||
"""Run the thing.""" | ||
|
@@ -377,9 +379,6 @@ def main(): | |
recur_dir = os.path.abspath(os.path.expanduser(CONFIG['recur_dir'])) | ||
pkg_arg = os.path.abspath(os.path.expanduser(CONFIG['pkg_arg'])) | ||
|
||
if CONFIG['highlight']: | ||
apply_highlight_css() | ||
|
||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
os.chdir(tmpdirname) # genanki is very opinionated about where we are. | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want
==
, notis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh... coffeescript sneaks in ;-) I've pushed a fix