Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CodiMD export script
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
stgroup
misc
CodiMD export script
Commits
3a941074
Commit
3a941074
authored
2 years ago
by
Andreas Domanowski
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Add rudimentary implementation for importing to HedgeDoc
parent
669c1c4f
Branches
Branches containing commit
No related tags found
1 merge request
!1
Hedgedoc import
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
hedgedoc_import.py
+36
-0
36 additions, 0 deletions
hedgedoc_import.py
with
36 additions
and
0 deletions
hedgedoc_import.py
0 → 100644
+
36
−
0
View file @
3a941074
import
urllib.parse
import
urllib.request
import
os
from
pathlib
import
Path
def
traverse
():
md_dir
=
"
markdown
"
folder
=
os
.
path
.
join
(
os
.
getcwd
(),
md_dir
);
print
(
"
Trying to upload all files with extension
\"
.md
\"
in folder
\"
"
+
folder
+
"
\"
"
);
for
relative_filename
in
os
.
listdir
(
folder
):
if
relative_filename
.
endswith
(
"
.md
"
):
addressable_filename
=
os
.
path
.
join
(
folder
,
relative_filename
)
print
(
"
Trying to upload:
"
+
addressable_filename
)
markdown_content
=
Path
(
addressable_filename
).
read_text
()
free_url
=
Path
(
relative_filename
).
stem
import_document
(
free_url
,
markdown_content
)
def
import_document
(
hedgedoc_free_url
,
content
,
session_id
):
sanitized_free_url
=
hedgedoc_free_url
.
replace
(
"
"
,
"
%20
"
)
user_agent
=
'
Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)
'
url
=
'
https://md.inf.tu-dresden.de/notes/new/
'
+
sanitized_free_url
session_id
=
session_id
headers
=
{
'
User-Agent
'
:
user_agent
,
"
Cookie
"
:
f
"
connect.hedgeDoc.sid=
{
session_id
}
"
,
"
Content-Type
"
:
"
text/markdown
"
}
pkt
=
str
.
encode
(
content
)
req
=
urllib
.
request
.
Request
(
url
,
data
=
pkt
,
method
=
'
POST
'
,
headers
=
headers
)
with
urllib
.
request
.
urlopen
(
req
)
as
response
:
print
(
"
Go visit
"
+
response
.
url
+
"
with your browser in a logged-in session.
"
)
traverse
()
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