Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mooc-rr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
84524221613d58c87acfb7d2d0777c72
mooc-rr
Commits
4fe991d6
Commit
4fe991d6
authored
Mar 28, 2020
by
84524221613d58c87acfb7d2d0777c72
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
653203c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
0 deletions
+74
-0
md2html.py
journal/md2html.py
+74
-0
No files found.
journal/md2html.py
0 → 100644
View file @
4fe991d6
# coding: utf8
"""Extrait une strophe du fichier info.md et l'affiche dans firefox
Usage: python3 md2html.py nom_fichier.md [numéro_strophe]
La strophe à afficher est encadrée par un commentaire spécial dans info.md :
<!--:numéro_strophe:-->
strophe
<!--::numéro_strophe::-->
L'appel sans numéro de strophe donne la table des matières .
Auteur: B. Cordeau sur une idée de L. Pointal
"""
# Import ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import
sys
import
re
from
pathlib
import
Path
from
markdown
import
markdown
import
webbrowser
# Programme principal =========================================================
fichier_md
=
sys
.
argv
[
1
]
motif
=
'toc'
if
len
(
sys
.
argv
)
==
2
else
sys
.
argv
[
2
]
motif_deb
=
r"<!--:"
+
motif
+
":-->"
motif_fin
=
r"<!--::"
+
motif
+
"::-->"
deb
=
re
.
compile
(
motif_deb
)
fin
=
re
.
compile
(
motif_fin
)
infos
=
""
# chaîne résultat
dedans
=
False
with
open
(
fichier_md
,
encoding
=
'utf-8'
)
as
f
:
for
line
in
f
:
if
fin
.
match
(
line
):
break
if
dedans
:
infos
+=
line
if
deb
.
match
(
line
):
dedans
=
True
path
=
Path
(
sys
.
argv
[
1
])
fichier
=
path
.
name
.
split
(
"."
)[
0
]
titre
=
"TOC"
if
len
(
sys
.
argv
)
==
2
else
fichier
+
" n° "
+
sys
.
argv
[
2
]
entete
=
"""
\
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>"""
+
titre
+
"""</title>
</head>
<body>
"""
body
=
markdown
(
infos
)
enbas
=
"""
\
</body>
</html>
"""
page
=
entete
+
body
+
enbas
with
open
(
"page.html"
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
page
)
webbrowser
.
open
(
"page.html"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment