Compare commits

..

No commits in common. "main" and "V3.2.9" have entirely different histories.
main ... V3.2.9

10 changed files with 121 additions and 171 deletions

View File

@ -1,29 +1,31 @@
name: Publish to PyPI on main branch update
name: Upload Python Package
on:
push:
branches:
- main
release:
types: [published]
permissions:
contents: read
jobs:
build_and_publish:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11' # 指定你需要的Python版本
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build package
run: python setup.py sdist bdist_wheel
- name: Publish to PyPI
run: |
twine upload -u __token__ -p ${{ secrets.PYPI_TOKEN }} dist/*
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: pypi-AgEIcHlwaS5vcmcCJDYxNjk2MzExLTg2NjMtNDUwNi1hMTQ0LTM2NDkxY2U1NjExYwACKlszLCIwNmJkMmFkZS1hYjkxLTQ0MWMtOWM1ZC02MmE0OTc3NTc5Y2EiXQAABiD_N8XZktPwthdp9dRpkpm7dIEh3eVbSr-X6H_OS8OzDw

View File

@ -10,7 +10,4 @@
<orderEntry type="jdk" jdkName="Python 3.11 (CrossDown)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PackageRequirementsSettings">
<option name="versionSpecifier" value="大于或等于 (&gt;=x.y.z)" />
</component>
</module>

View File

@ -2,15 +2,16 @@
核心代码
"""
import re
import xml
from typing import *
import markdown.core
from markdown import Markdown
from markdown.blockprocessors import BlockProcessor
from markdown.extensions import Extension, meta, toc, wikilinks, legacy_attrs
from markdown.inlinepatterns import InlineProcessor
from markdown.preprocessors import Preprocessor
from pymdownx.arithmatex import ArithmatexExtension
from pymdownx.blocks import BlocksExtension
@ -36,13 +37,7 @@ from pymdownx.tilde import DeleteSubExtension
from pymdownx.magiclink import MagiclinkExtension
from pymdownx.pathconverter import PathConverterExtension
import kbdextension
import markdown_gfm_admonition
from xml.etree.ElementTree import ElementTree
Variable = dict[str, str | tuple[str], list[str]] | None
from .Define import Variable
class Simple(InlineProcessor):
@ -110,7 +105,7 @@ class ID(InlineProcessor):
需要对HTML标签设置ID实现的样式
"""
def __init__(self, pattern: str, tag: str, property_: str, value: str | bool = None):
def __init__(self, pattern: str, tag: str, property_: str, value: Union[str, bool] = None):
"""
初始化
:param pattern: 正则表达式
@ -166,6 +161,44 @@ class Syllabus(BlockProcessor):
return False
class Anchor(InlineProcessor):
"""
{#定义锚点}
"""
def handleMatch(self, m: Match[str], data: str) -> (Tuple[xml.etree.ElementTree.Element, int, int] |
Tuple[None, None, None]):
"""
处理匹配
:param m: re模块的匹配对象
:param data: 被匹配的原始文本
:return: 标签 匹配开始 匹配结束
"""
tag = xml.etree.ElementTree.Element('span') # 创建标签
tag.text = m.group(1)
tag.set('id', m.group(1)) # 设置id
return tag, m.start(), m.end()
class LinkLine(InlineProcessor):
"""
{行内链接}
"""
def handleMatch(self, m: Match[str], data: str) -> (Tuple[xml.etree.ElementTree.Element, int, int] |
Tuple[None, None, None]):
"""
处理匹配
:param m: re模块的匹配对象
:param data: 被匹配的原始文本
:return: 标签 匹配开始 匹配结束
"""
tag = xml.etree.ElementTree.Element('a') # 创建标签
tag.set('href', '#' + m.group(1)) # 设置id
tag.text = m.group(1)
return tag, m.start(), m.end()
class BasicExtension(Extension):
"""
渲染基本样式
@ -186,31 +219,15 @@ class BasicExtension(Extension):
md.parser.blockprocessors.register(Syllabus(md.parser), 'syllabus', 182) # 渲染提纲
class InlineCode:
def __init__(self, variable: Variable):
self.variable = variable
def __call__(self, source: str, language: str, css_class: str, md: markdown.core.Markdown): # 自定义的单行代码格式化器
if language != '': # 调用默认格式化函数
return md.inlinePatterns['backtick'].highlight_code(
src=source, language=language, classname=css_class,
md=md
)
match tuple(source):
case '{', '#', *archers, '}': # 匹配到{#锚点}
archer = ''.join(archers)
return f'<span id="{archer}">{archer}</span>'
case '{', '-', *inline_links, '}': # 匹配到{-行内链接}
inline_link = ''.join(inline_links)
return f'<a href=#{inline_link}>{inline_link}</a>'
case '{', *variables, '}': # 匹配到{变量}
variable = ''.join(variables)
if variable in self.variable:
return self.variable[variable]
else:
return variable
case _:
return f'<code>{source}</code>'
class AnchorExtension(Extension):
def extendMarkdown(self, md: Markdown):
"""
添加扩展
:param md: 转换器
"""
md.registerExtension(self) # 注册扩展
md.inlinePatterns.register(Anchor(r'\{{#([^{}#]+)}}'), 'anchor', 0) # 定义锚点
md.inlinePatterns.register(LinkLine(r'\{{([^{}#]+)}}'), 'line_link', 0) # 添加页内链接
Extensions = {
@ -227,8 +244,8 @@ Extensions = {
{
'name': 'mermaid',
'class': 'mermaid',
'format': fence_div_format,
},
'format': fence_div_format
}
]
},
}),
@ -241,6 +258,7 @@ Extensions = {
'标签': TabExtension(),
'批评': CriticExtension(),
'代码高亮': HighlightExtension(),
'行内高亮': InlineHiliteExtension(),
'按键风格': KeysExtension(),
'高亮': MarkExtension(),
'进度条': ProgressBarExtension(),
@ -253,16 +271,13 @@ Extensions = {
'超级链接': MagiclinkExtension(),
'路径转换器': PathConverterExtension(),
# 其它
'KBD': kbdextension.KbdExtension(),
'GFM 警告': markdown_gfm_admonition.GfmAdmonitionExtension(),
# 自定义
'基本风格': BasicExtension(),
'锚点': AnchorExtension(),
}
def main(text: str, variable: Variable = None) -> tuple[str, Variable]:
def main(text: str, variable: Variable = None) -> Tuple[str, Variable]:
"""
主函数
:param text: 输入文本
@ -271,15 +286,5 @@ def main(text: str, variable: Variable = None) -> tuple[str, Variable]:
"""
if variable is None:
variable = {}
md = Markdown(extensions=list(Extensions.values()) + [
InlineHiliteExtension(
custom_inline=[
{
'name': '*',
'class': 'block',
'format': InlineCode(variable=variable),
},
]
),
])
md = Markdown(extensions=list(Extensions.values()))
return md.convert(text), md.Meta

4
CrossDown/Define.py Normal file
View File

@ -0,0 +1,4 @@
from typing import *
Variable = Dict[str, Union[str, Tuple[str], List[str]]] | None

View File

@ -1,14 +1,12 @@
from typing import *
import pickle
from .Core import main, Variable, Syllabus
from .Core import main
__all__ = [
'main', # 主函数
'indent', # 添加空格
'HEAD', # HTML头部引用
'Meta', # 元数据处理器
'Syllabus', # 提纲扩展
'Variable', # 变量类型提示
]
__version__ = '0.11.2'
__author__ = 'CrossDark'

View File

@ -61,7 +61,7 @@
</li>
<li><a href="#3">3 锚点</a><ul>
<li><a href="#3.1">3.1 定义</a></li>
<li><a href="#3.2">3.2 链接</a></li>
<li><a href="#3.2">3.2 页内链接</a></li>
</ul>
</li>
<li><a href="#4">4 代码块</a><ul>
@ -132,14 +132,6 @@
</ul>
</li>
<li><a href="#19">19 批评</a></li>
<li><a href="#20">20 警告</a><ul>
<li><a href="#20.1">20.1 告示</a></li>
<li><a href="#20.2">20.2 提示</a></li>
<li><a href="#20.3">20.3 着重</a></li>
<li><a href="#20.4">20.4 提醒</a></li>
<li><a href="#20.5">20.5 警告</a></li>
</ul>
</li>
</ul>
</div>
<h1 id="crossdown">CrossDown</h1>
@ -187,9 +179,9 @@
<p>直接在文本中使用 <abbr title="长的文本">缩写</abbr> 即可</p>
<h1 id="3">3 锚点</h1>
<h2 id="3.1">3.1 定义</h2>
<p><span id="锚点">锚点</span></p>
<h2 id="3.2">3.2 链接</h2>
<p><a href=#锚点>锚点</a></p>
<p><span id="锚点">锚点</span></p>
<h2 id="3.2">3.2 页内链接</h2>
<p><a href="#锚点名">锚点</a></p>
<h1 id="4">4 代码块</h1>
<h2 id="4.1">4.1 <code>单行</code></h2>
<p>Here is some code: <code class="highlight"><span class="kn">import</span> <span class="nn">pymdownx</span><span class="p">;</span> <span class="n">pymdownx</span><span class="o">.</span><span class="n">__version__</span></code>.</p>
@ -205,19 +197,21 @@
<p><code>¥y=x**3¥€-50,50|-100,100€</code> // 定义了y范围</p>
<h3 id="4.1.3">4.1.3 按键风格</h3>
<p><span class="keys"><kbd class="key-control">Ctrl</kbd><span>+</span><kbd class="key-alt">Alt</kbd><span>+</span><kbd class="key-delete">Del</kbd></span></p>
<p><kbd>Enter</kbd></p>
<h3 id="4.1.4">4.1.4 突出</h3>
<p>突出内容</p>
<p><code>{突出内容}</code></p>
<h2 id="4.2">4.2 多行</h2>
<h3 id="4.2.1">4.2.1 YAML</h3>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">2</span>
<span class="normal">3</span>
<span class="normal">4</span>
<span class="normal">5</span>
<span class="normal">6</span>
<span class="normal">7</span>
<span class="normal">8</span>
<span class="normal">9</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="hll"><span class="nt">A</span><span class="p">:</span>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"> 2</span>
<span class="normal"> 3</span>
<span class="normal"> 4</span>
<span class="normal"> 5</span>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="hll"><span class="nt">A</span><span class="p">:</span>
</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1. a</span>
<span class="hll"><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">2. b</span>
</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">3. c</span>
@ -225,6 +219,9 @@
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">a</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">b</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">c</span>
<span class="p p-Indicator">{[</span><span class="nv">强调变量</span><span class="p p-Indicator">]}:</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">a</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">b</span>
</code></pre></div></td></tr></table></div>
<h3 id="4.2.2">4.2.2 Python</h3>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span>
@ -266,7 +263,7 @@
p(h_j=1|\mathbf{v}) & = \sigma\left(\sum_i w_{ij}v_i + c_j\right)
\end{align}</script>
</div>
<p>行内公式: <span class="arithmatex"><span class="MathJax_Preview">p(x|y) = \frac{p(y|x)p(x)}{p(y)}</span><script type="math/tex">p(x|y) = \frac{p(y|x)p(x)}{p(y)}</script></span></p>
<p>行内公式: <span class="arithmatex"><span class="MathJax_Preview">p(x|y) = \frac{p(y|x)p(x)}{p(y)}</span><script type="math/tex">p(x|y) = \frac{p(y|x)p(x)}{p(y)}</script></span> </p>
<h3 id="4.2.6">4.2.6 HTML</h3>
<div class="highlight"><pre><span></span><code><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<span class="cm">&lt;!--头部--&gt;</span>
@ -314,7 +311,7 @@
<p>7.1.3. 错误示范</p>
<p>不能出现两个及以上连续的点,例如:</p>
<p>7..1...4 错误示范</p>
<p>提纲号会被自动配置为锚点,可直接使用{-7}{-7.1}</p>
<p>提纲号会被自动配置为锚点,可直接使用<a href="#7">7</a><a href="#7.1">7.1</a></p>
<h1 id="8">8 注释</h1>
<!-- 这是注释 -->
@ -355,7 +352,7 @@
<li>c</li>
</ul>
</dd>
<dt>强调值</dt>
<dt><code>{强调变量}</code></dt>
<dd>
<ul>
<li>a</li>
@ -549,7 +546,7 @@
</div>
</p>
<h1 id="15">15 内部链接</h1>
<p><kbd>Bracketed</kbd></p>
<p><a class="wikilink" href="/Bracketed/">Bracketed</a></p>
<h1 id="16">16 变量</h1>
<p>{[强调变量]}</p>
<h1 id="17">17 属性设置</h1>
@ -623,31 +620,5 @@
<li>test add</li>
</ul>
</ins>
<h1 id="20">20 警告</h1>
<h2 id="20.1">20.1 告示</h2>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>突出用户应考虑的信息</p>
</div>
<h2 id="20.2">20.2 提示</h2>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>帮助用户的可选信息</p>
</div>
<h2 id="20.3">20.3 着重</h2>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>Crucial information necessary for users to succeed.</p>
</div>
<h2 id="20.4">20.4 提醒</h2>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Critical content demanding immediate user attention due to potential risks.</p>
</div>
<h2 id="20.5">20.5 警告</h2>
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<p>Negative potential consequences of an action.</p>
</div>
</body>
</html>

View File

@ -92,11 +92,11 @@ liuhanbo333@icloud.com
3.1 定义
`{#锚点}`
{{#锚点名}}
3.2 链接
3.2 页内链接
`{-锚点}`
{{锚点名}}
4 代码块
@ -127,8 +127,6 @@ $\lg\left(\frac{目标生物的理智值}{稳定折磨型工具人的理智值}\
++ctrl+alt+delete++
[[Enter]]
4.1.4 突出
`{突出内容}`
@ -146,6 +144,9 @@ B:
- a
- b
- c
{[强调变量]}:
- a
- b
```
4.2.2 Python
@ -186,7 +187,7 @@ $$
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)}$
行内公式: $p(x|y) = \frac{p(y|x)p(x)}{p(y)}$
4.2.6 HTML
@ -245,7 +246,7 @@ def main():
7..1...4 错误示范
提纲号会被自动配置为锚点,可直接使用{-7}{-7.1}
提纲号会被自动配置为锚点,可直接使用{{7}}{{7.1}}
8 注释
@ -497,30 +498,3 @@ General block handling.
* test add
++}
20 警告
20.1 告示
> [!NOTE]
> 突出用户应考虑的信息
20.2 提示
> [!TIP]
> 帮助用户的可选信息
20.3 着重
> [!IMPORTANT]
> Crucial information necessary for users to succeed.
20.4 提醒
> [!WARNING]
> Critical content demanding immediate user attention due to potential risks.
20.5 警告
> [!CAUTION]
> Negative potential consequences of an action.

BIN
data.pkl

Binary file not shown.

View File

@ -5,5 +5,4 @@ pygments>=2.18.0
CrossDown>=2.2.0
setuptools~=70.1.1
emoji~=2.13.2
pymdown-extensions>=10.12
kbdextension>=1.0.1
pymdown-extensions>=10.12

View File

@ -2,7 +2,7 @@ import setuptools
from CrossDown import Meta
meta = Meta(3, 3, 2)
meta = Meta(3, 2, 9)
setuptools.setup(
name="CrossDown",