Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions mkdocs_pandoc/filters/math.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2015 Johannes Grassler <[email protected]>
# Copyright 2016 Kergonath <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import re

class MathFilter(object):
"""Turn the \( \) Markdown math notation into LaTex $$ inlines"""

def run(self, lines):
"""Filter method"""
ret = []
for line in lines:
ret.append(re.sub(r'\\\((.*)\\\)', r'$\1$', line))

return ret
34 changes: 34 additions & 0 deletions mkdocs_pandoc/filters/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2015 Johannes Grassler <[email protected]>
# Copyright 2016 Kergonath <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import re

class MetadataFilter(object):
"""Turn the \( \) Markdown math notation into LaTex $$ inlines"""

def run(self, lines):
"""Filter method"""
ret = []
header = True
for line in lines:
if header:
if not re.match(r'^[a-zA-Z\ ]:', line):
header = False
ret.append(line)
else:
ret.append(line)

return ret
11 changes: 10 additions & 1 deletion mkdocs_pandoc/pandoc_converter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import mkdocs_pandoc.filters.anchors
import mkdocs_pandoc.filters.math
import mkdocs_pandoc.filters.chapterhead
import mkdocs_pandoc.filters.headlevels
import mkdocs_pandoc.filters.images
import mkdocs_pandoc.filters.metadata
import mkdocs_pandoc.filters.exclude
import mkdocs_pandoc.filters.include
import mkdocs_pandoc.filters.tables
Expand All @@ -26,6 +28,8 @@ def __init__(self, **kwargs):
self.filter_xrefs = kwargs.get('filter_xrefs', True)
self.image_ext = kwargs.get('image_ext', None)
self.strip_anchors = kwargs.get('strip_anchors', True)
self.strip_metadata = kwargs.get('strip_metadata', True)
self.convert_math = kwargs.get('convert_math', True)
self.width = kwargs.get('width', 100)

try:
Expand Down Expand Up @@ -133,7 +137,8 @@ def convert(self):

if self.filter_include:
lines_tmp = f_include.run(lines_tmp)


lines_tmp = mkdocs_pandoc.filters.metadata.MetadataFilter().run(lines_tmp)
lines_tmp = f_headlevel.run(lines_tmp)
lines_tmp = f_chapterhead.run(lines_tmp)
lines_tmp = f_image.run(lines_tmp)
Expand All @@ -146,6 +151,10 @@ def convert(self):
if self.strip_anchors:
lines = mkdocs_pandoc.filters.anchors.AnchorFilter().run(lines)

# Convert math expressions
if self.convert_math:
lines = mkdocs_pandoc.filters.math.MathFilter().run(lines)

# Fix cross references
if self.filter_xrefs:
lines = mkdocs_pandoc.filters.xref.XrefFilter().run(lines)
Expand Down