Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pdf-miner
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
Qin Kaijie
pdf-miner
Commits
59b0b0c3
Commit
59b0b0c3
authored
Mar 14, 2024
by
赵小蒙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make markdown时特殊符号转义
parent
8a2736a5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
ocr_mkcontent.py
magic_pdf/dict2md/ocr_mkcontent.py
+3
-2
markdown_utils.py
magic_pdf/libs/markdown_utils.py
+11
-0
No files found.
magic_pdf/dict2md/ocr_mkcontent.py
View file @
59b0b0c3
from
magic_pdf.libs.markdown_utils
import
ocr_escape_special_markdown_char
from
magic_pdf.libs.ocr_content_type
import
ContentType
...
...
@@ -14,7 +15,7 @@ def ocr_mk_nlp_markdown(pdf_info_dict: dict):
for
span
in
line
[
'spans'
]:
if
not
span
.
get
(
'content'
):
continue
content
=
span
[
'content'
]
.
replace
(
'$'
,
'
\
$'
)
# 转义$
content
=
ocr_escape_special_markdown_char
(
span
[
'content'
])
# 转义特殊符号
if
span
[
'type'
]
==
ContentType
.
InlineEquation
:
content
=
f
"${content}$"
elif
span
[
'type'
]
==
ContentType
.
InterlineEquation
:
...
...
@@ -43,7 +44,7 @@ def ocr_mk_mm_markdown(pdf_info_dict: dict):
else
:
content
=
f
""
else
:
content
=
span
[
'content'
]
.
replace
(
'$'
,
'
\
$'
)
# 转义$
content
=
ocr_escape_special_markdown_char
(
span
[
'content'
])
# 转义特殊符号
if
span
[
'type'
]
==
ContentType
.
InlineEquation
:
content
=
f
"${content}$"
elif
span
[
'type'
]
==
ContentType
.
InterlineEquation
:
...
...
magic_pdf/libs/markdown_utils.py
View file @
59b0b0c3
...
...
@@ -18,3 +18,14 @@ def escape_special_markdown_char(pymu_blocks):
span
[
'text'
]
=
span
[
'text'
]
.
replace
(
char
,
"
\\
"
+
char
)
return
pymu_blocks
def
ocr_escape_special_markdown_char
(
content
):
"""
转义正文里对markdown语法有特殊意义的字符
"""
special_chars
=
[
"*"
,
"`"
,
"~"
,
"$"
]
for
char
in
special_chars
:
content
=
content
.
replace
(
char
,
"
\\
"
+
char
)
return
content
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