forked from CrossDark/CrossDown
3.1 使用pymdownx
This commit is contained in:
parent
2017c80724
commit
b885051c67
@ -1,5 +1,15 @@
|
||||
from markdown.extensions import Extension, extra, admonition, meta, sane_lists, toc, wikilinks, codehilite, legacy_attrs
|
||||
|
||||
from pymdownx.arithmatex import ArithmatexExtension
|
||||
from pymdownx.emoji import EmojiExtension
|
||||
from pymdownx.blocks import BlocksExtension
|
||||
from pymdownx.blocks.admonition import AdmonitionExtension
|
||||
from pymdownx.blocks.definition import DefinitionExtension
|
||||
from pymdownx.blocks.details import DetailsExtension
|
||||
from pymdownx.blocks.html import HTMLExtension
|
||||
from pymdownx.blocks.tab import TabExtension
|
||||
from pymdownx.caret import CaretProcessor
|
||||
from pymdownx.critic import CriticExtension
|
||||
|
||||
from pygments.formatters import HtmlFormatter
|
||||
|
||||
@ -49,9 +59,9 @@ class HighlightHtmlFormatter(HtmlFormatter):
|
||||
Extensions = {
|
||||
# 自带
|
||||
'基本扩展': extra.ExtraExtension(fenced_code={'lang_prefix': ''}),
|
||||
'警告扩展': admonition.AdmonitionExtension(),
|
||||
# '警告扩展': admonition.AdmonitionExtension(),
|
||||
'元数据': meta.MetaExtension(),
|
||||
'能列表': sane_lists.SaneListExtension(),
|
||||
# '能列表': sane_lists.SaneListExtension(),
|
||||
'目录': toc.TocExtension(),
|
||||
'内部链接': wikilinks.WikiLinkExtension(),
|
||||
# '代码高亮': codehilite.CodeHiliteExtension(guess_lang=False, pygments_formatter=HighlightHtmlFormatter),
|
||||
@ -59,11 +69,20 @@ Extensions = {
|
||||
|
||||
# pymdownx
|
||||
'超级数学': ArithmatexExtension(),
|
||||
'EMOJI': EmojiExtension(),
|
||||
'块扩展': BlocksExtension(),
|
||||
'警告': AdmonitionExtension(),
|
||||
'定义列表': DefinitionExtension(),
|
||||
'详情': DetailsExtension(),
|
||||
'HTML': HTMLExtension(),
|
||||
'标签': TabExtension(),
|
||||
'批评': CriticExtension(),
|
||||
}
|
||||
|
||||
|
||||
class PreProcess(Preprocessor):
|
||||
"""预处理"""
|
||||
|
||||
def __init__(self, variable: Variable):
|
||||
super().__init__()
|
||||
self.variable = variable
|
||||
@ -94,7 +113,8 @@ class Simple(InlineProcessor):
|
||||
super().__init__(pattern)
|
||||
self.tag = tag
|
||||
|
||||
def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[None, None, None]:
|
||||
def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[
|
||||
None, None, None]:
|
||||
"""
|
||||
处理匹配
|
||||
:param m: re模块的匹配对象
|
||||
@ -123,7 +143,8 @@ class Nest(InlineProcessor):
|
||||
self.outer_tag = outer_tag
|
||||
self.inner_tag = inner_tag
|
||||
|
||||
def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[None, None, None]:
|
||||
def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[
|
||||
None, None, None]:
|
||||
"""
|
||||
处理匹配
|
||||
:param m: re模块的匹配对象
|
||||
@ -156,7 +177,8 @@ class ID(InlineProcessor):
|
||||
self.property = property_
|
||||
self.value = value
|
||||
|
||||
def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[None, None, None]:
|
||||
def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[
|
||||
None, None, None]:
|
||||
"""
|
||||
处理匹配
|
||||
:param m: re模块的匹配对象
|
||||
@ -182,7 +204,8 @@ class Emoji(InlineProcessor):
|
||||
"""
|
||||
super().__init__(pattern)
|
||||
|
||||
def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[None, None, None]:
|
||||
def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[
|
||||
None, None, None]:
|
||||
"""
|
||||
处理匹配
|
||||
:param m: re模块的匹配对象
|
||||
@ -272,7 +295,8 @@ class BoxBlock(BlockProcessor):
|
||||
|
||||
|
||||
class _Anchor(InlineProcessor):
|
||||
def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[None, None, None]:
|
||||
def handleMatch(self, m: Match[str], data: str) -> Tuple[xml.etree.ElementTree.Element, int, int] | Tuple[
|
||||
None, None, None]:
|
||||
"""
|
||||
处理匹配
|
||||
:param m: re模块的匹配对象
|
||||
@ -357,6 +381,7 @@ class CodeBlock(Treeprocessor):
|
||||
"""
|
||||
渲染单行代码
|
||||
"""
|
||||
|
||||
def run(self, root: xml.etree.ElementTree.Element):
|
||||
for code in root:
|
||||
print(code.text)
|
||||
@ -364,6 +389,7 @@ class CodeBlock(Treeprocessor):
|
||||
|
||||
class Pre(Extension):
|
||||
"""预处理"""
|
||||
|
||||
def __init__(self, variable: Variable):
|
||||
"""
|
||||
初始化
|
||||
@ -401,7 +427,7 @@ class Basic(Extension):
|
||||
md.inlinePatterns.register(ID(
|
||||
r'\[(.*?)]-\((.*?)\)', tag='span', property_='title'), 'hide', 180
|
||||
) # [在指定的文本里面隐藏一段文本]-(只有鼠标放在上面才会显示隐藏文本)
|
||||
md.inlinePatterns.register(Emoji(r':(.+?):'), 'emoji', 181) # 将emoji短代码转换为emoji字符
|
||||
# md.inlinePatterns.register(Emoji(r':(.+?):'), 'emoji', 181) # 将emoji短代码转换为emoji字符
|
||||
md.parser.blockprocessors.register(Syllabus(md.parser), 'syllabus', 182) # 渲染提纲
|
||||
|
||||
|
||||
@ -475,8 +501,8 @@ class Code(Extension):
|
||||
:param md: 转换器
|
||||
"""
|
||||
md.registerExtension(self) # 注册扩展
|
||||
md.treeprocessors.register(CodeLine(variable=self.variable), 'code_line', 0) # 渲染单行代码块
|
||||
md.treeprocessors.register(CodeBlock(), 'code_block', 1000) # 渲染多行代码块
|
||||
# md.treeprocessors.register(CodeLine(variable=self.variable), 'code_line', 0) # 渲染单行代码块
|
||||
# md.treeprocessors.register(CodeBlock(), 'code_block', 1000) # 渲染多行代码块
|
||||
|
||||
|
||||
def main(text: str, variable: Variable = None) -> Tuple[str, Variable]:
|
||||
|
208
README.html
208
README.html
File diff suppressed because one or more lines are too long
129
README.md
129
README.md
@ -158,32 +158,18 @@ ls
|
||||
|
||||
4.2.5 latex
|
||||
|
||||
```latex-rd
|
||||
\documentclass{article}
|
||||
\title{我的第一个LaTeX文档}
|
||||
\author{作者姓名}
|
||||
\date{\today}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
这是我的第一个LaTeX文档。它包含了一个标题、作者信息、日期和一个简单的正文部分。
|
||||
|
||||
\section{引言}
|
||||
|
||||
这是引言部分,可以简要介绍文档的主题和目的。
|
||||
|
||||
\section{正文}
|
||||
|
||||
这是正文部分,可以详细阐述你的观点或研究内容。你可以根据需要添加更多的章节和子章节。
|
||||
|
||||
\subsection{子章节示例}
|
||||
|
||||
这是一个子章节的示例,用于展示如何在LaTeX文档中创建层次结构。
|
||||
|
||||
\end{document}
|
||||
```
|
||||
$$
|
||||
E(\mathbf{v}, \mathbf{h}) = -\sum_{i,j}w_{ij}v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
|
||||
$$
|
||||
|
||||
\[3 < 4\]
|
||||
|
||||
\begin{align}
|
||||
p(v_i=1|\mathbf{h}) & = \sigma\left(\sum_j w_{ij}h_j + b_i\right) \\
|
||||
p(h_j=1|\mathbf{v}) & = \sigma\left(\sum_i w_{ij}v_i + c_j\right)
|
||||
\end{align}
|
||||
|
||||
行内公式: $p(x|y) = \frac{p(y|x)p(x)}{p(y)}$
|
||||
|
||||
4.2.6 HTML
|
||||
|
||||
@ -311,9 +297,9 @@ Orange
|
||||
|
||||
12 Emoji
|
||||
|
||||
:person_biking:
|
||||
:smile: :heart: :thumbsup:
|
||||
|
||||
这是一个笑脸:grinning_face_with_big_eyes:图案
|
||||
这是一个笑脸 :smile: 图案
|
||||
|
||||
13 脚注
|
||||
|
||||
@ -384,3 +370,90 @@ Orange
|
||||
可以设置文段的自定义字体{@style=font-family: SetoFont;}为小赖字体
|
||||
|
||||
可以设置文本的黄色外框{@style=display: inline-block; border: 1px solid yellow;}
|
||||
|
||||
18 超级块
|
||||
|
||||
18.1 警告
|
||||
|
||||
/// note | Did you know?
|
||||
You can create a note with Blocks!
|
||||
///
|
||||
|
||||
18.2 定义列表
|
||||
|
||||
/// define
|
||||
Apple
|
||||
|
||||
- Pomaceous fruit of plants of the genus Malus in
|
||||
the family Rosaceae.
|
||||
|
||||
Orange
|
||||
|
||||
- The fruit of an evergreen tree of the genus Citrus.
|
||||
|
||||
///
|
||||
|
||||
18.3 详情
|
||||
|
||||
/// details | Some summary
|
||||
type: warning
|
||||
|
||||
Some content
|
||||
///
|
||||
|
||||
18.4 HTML
|
||||
|
||||
/// html | div[style='border: 1px solid red;']
|
||||
some *markdown* content
|
||||
///
|
||||
|
||||
18.5 标签
|
||||
|
||||
/// tab | Tab A title
|
||||
Tab A content
|
||||
///
|
||||
|
||||
/// tab | Tab B title
|
||||
Tab B content
|
||||
///
|
||||
|
||||
/// tab | Tab C Title
|
||||
new: true
|
||||
|
||||
Will be part of a separate, new tab group.
|
||||
///
|
||||
|
||||
19 批评
|
||||
|
||||
Here is some {--*incorrect*--} Markdown. I am adding this{++ here++}. Here is some more {--text
|
||||
that I am removing--}text. And here is even more {++text that I
|
||||
am ++}adding.{~~
|
||||
|
||||
~> ~~}Paragraph was deleted and replaced with some spaces.{~~ ~>
|
||||
|
||||
~~}Spaces were removed and a paragraph was added.
|
||||
|
||||
And here is a comment on {==some
|
||||
text==}{>>This works quite well. I just wanted to comment on it.<<}. Substitutions {~~is~>are~~} great!
|
||||
|
||||
General block handling.
|
||||
|
||||
{--
|
||||
|
||||
* test remove
|
||||
* test remove
|
||||
* test remove
|
||||
* test remove
|
||||
* test remove
|
||||
|
||||
--}
|
||||
|
||||
{++
|
||||
|
||||
* test add
|
||||
* test add
|
||||
* test add
|
||||
* test add
|
||||
* test add
|
||||
|
||||
++}
|
||||
|
Loading…
Reference in New Issue
Block a user