Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SWIFTweb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTweb
Commits
c07d6b29
Commit
c07d6b29
authored
7 years ago
by
Josh Borrow
Browse files
Options
Downloads
Patches
Plain Diff
added mistune as a possible markdown renderer (it's python only)
parent
5a96bdb0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
about.py
+12
-11
12 additions, 11 deletions
about.py
mdcomp.py
+51
-0
51 additions, 0 deletions
mdcomp.py
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
with
64 additions
and
11 deletions
about.py
+
12
−
11
View file @
c07d6b29
"""
This file contains the routines used to compile the
'
about
'
page
'
s text.
This text comes to us in three parts, which are stored in three markdown
files in the data directory, along with an about_meta.yaml file describing
how they are to be described at the top of the page.
"""
This file contains the routines used to compile the
'
about
'
page
'
s text.
This text comes to us in three parts, which are stored in three markdown
files in the data directory, along with an about_meta.yaml file describing
how they are to be described at the top of the page.
The markdown files are then compiled to two pieces of HTML, one for the
sidebar and one for the main part of the text, as well as a small
dictionary that describes the content of the cards at the top of the page.
The markdown files are then compiled to two pieces of HTML, one for the
sidebar and one for the main part of the text, as well as a small
dictionary that describes the content of the cards at the top of the page.
Created 16-08-2017 by Josh Borrow (joshua.borrow@durham.ac.uk)
Created 16-08-2017 by Josh Borrow (joshua.borrow@durham.ac.uk)
"""
#Disable errors associated with un-overwritten methods in HTMLParser.
...
...
@@ -15,7 +16,7 @@
from
html.parser
import
HTMLParser
import
pypandoc
from
mdcomp
import
convert_text
import
yaml
...
...
@@ -33,8 +34,8 @@ def compile_markdown(data, data_dir="../data"):
for
item
in
data
[
"
files
"
]:
with
open
(
f
"
{
data_dir
}
/
{
item
[
'
name
'
]
}
"
,
"
r
"
)
as
handle
:
input_text
=
handle
.
read
()
compiled_text
=
pypandoc
.
convert_text
(
input_text
,
'
html
'
,
format
=
'
md
'
)
compiled_text
=
convert_text
(
input_text
)
output_text
+=
f
"
<div id=
\"
{
item
[
'
slug
'
]
}
\"
>
{
compiled_text
}
</div>
"
return
output_text
...
...
This diff is collapsed.
Click to expand it.
mdcomp.py
0 → 100644
+
51
−
0
View file @
c07d6b29
"""
Allows for us to switch between pandoc and mistune nicely.
If the user does not have pandoc installed, we want to use mistune. The
problem there is that mistune does not have the automatic id plugin
for headings that we use to generate sidebars, i.e.
## HEAD
gets converted to
<h2>HEAD</h2>
not
<h2 id=
"
head
"
>HEAD</h2>
like it does within pandoc.
Created 22-09-2017 by Josh Borrow (joshua.borrow@durham.ac.uk)
"""
try
:
import
pypandoc
test
=
pypandoc
.
convert_text
(
"
hello
"
,
"
html
"
,
format
=
"
md
"
)
def
convert_text
(
input_text
):
return
pypandoc
.
convert_text
(
input_text
,
"
html
"
,
format
=
"
md
"
)
except
OSError
:
print
(
"
Pandoc not found on your system. Using mistune (python-only)
"
)
import
mistune
class
IDRenderer
(
mistune
.
Renderer
):
def
header
(
self
,
text
,
level
,
raw
=
None
):
text
=
"
<h{} id={}>{}</h{}>
"
.
format
(
level
,
(
text
.
replace
(
"
"
,
"
-
"
)).
lower
(),
text
,
level
)
return
text
renderer
=
IDRenderer
()
markdown
=
mistune
.
Markdown
(
renderer
=
renderer
)
def
convert_text
(
input_text
):
return
markdown
(
input_text
)
This diff is collapsed.
Click to expand it.
requirements.txt
+
1
−
0
View file @
c07d6b29
pyyaml
jinja2
pypandoc
mistune
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment