Compare commits
8
Commits
b1d71ce641
...
26.11.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5977b1b272 | ||
|
|
97e84fa6c4 | ||
|
|
173c7a042d | ||
|
|
a4179abb06 | ||
|
|
fe34ccc38a | ||
|
|
178a8f5e19 | ||
|
|
03de63f48f | ||
|
|
99c59d443d |
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 120 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 116 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 172 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 131 KiB |
@@ -1,14 +1,13 @@
|
||||
# 工厂通讯:一个发展巴布石金式工人同志的案例
|
||||
## 编者按:
|
||||
|
||||
编者按:
|
||||
同志A完全信任我们的工人同志,我们认为主要源于这位同志长时间的沟通,以及他偶然注意到A的留言动态,通过内容来判断,由此进行关心。在这个基础上,我们有充分的理由相信,同志在做思想工作的过程中,应当是没有架子,做到了群众化的。在A的视角,我们的同志只是具备理论知识的打工人,他们之间是可以“随意”交流的,在他们的沟通和相处中,我们的同志取得了A的信任。为什么他能够得到信任呢?在客观上,是A的部分改良主义思想破产及资产阶级爱情观的打击,在主观上,我们的同志及时注意到了同志A的情绪低落状态,然后在这个节点,采用了解和关心的方式方法,首先在情感上取得了A的信任,在这个基础上,逐渐从情绪或者说从感性的层面,逐步发展为理性的灌输阶段。
|
||||
并且同志A在现实中遇到的各种问题,我们的同志也可以解释并很好地回应,这反映出在对待同志A的工作中,同志的方式方法充分得到了现实的结果支撑。总之,这次成果主要来源于对现有感性材料的合理判断,加上同志的主观努力。这也说明了具体的灌输工作的曲折性:在不同的工人之间,这种灌输往往并不是直线的,所以需要注意保持恒心,善于发现工友关注的矛盾的点,并进行针对性的交流,这点需要我们在实际工作中不断锻炼。
|
||||
|
||||
说明:
|
||||
>
|
||||
> - 我 - 厂内同志
|
||||
> - 同志A - 我本地发展的工人同志
|
||||
> 之所以开始写这个问题,是因为我这边发展的同志A的工作已经达到了较好的水平,可以做阶段汇报了。
|
||||
- 我 - 厂内同志
|
||||
- 同志A - 我本地发展的工人同志
|
||||
|
||||
之所以开始写这个问题,是因为我这边发展的同志A的工作已经达到了较好的水平,可以做阶段汇报了。
|
||||
|
||||
## 一、当前的工作进展
|
||||
### 同志A已能够独立发展新同志
|
||||
@@ -66,7 +65,7 @@
|
||||
|
||||
他喜欢说在保安岗位上怎么不听老板的话,以及故意把车放走不收停车费让他们损失。但对导致自己离职或可能有财产损失的斗争就犹豫。我问他,他爱谈的那些斗争对于别人有什么帮助呢?他如果能通过斗争,使得他即使早走也能拿到工资,那以后也能教别人怎么做,这样才会对别人有帮助。实际上这就是因为他还是太顾自己,不够考虑别人,另外也不够考虑政治,只是考虑这点钱,为了这点钱而一直被他们拖着浪费时间。
|
||||
|
||||
3. 个人经历对革命路线的影响
|
||||
### 3. 个人经历对革命路线的影响
|
||||
**应该结合他生产上的地位来分析这些路线**,这位同志之前在工厂里做过,厂里有次几个人在厕所抽烟被抓了,本来说要罚款,大家都不同意,只好作罢。他也觉得厂里的人会比别的地方的更可能反抗。他说要是厂里人都罢工,资本家是没办法的,他只能求你动一下、动一下,工人就可以提出自己的诉求。不过他因为搞物业当保安,并且之前还和一些流氓无产阶级有交往,认识的人很杂。唯军事论、缺乏政治挂帅的路线就是来源于流氓无产阶级的影响,还有保安这种非生产的行业也会有无政府主义的倾向。
|
||||
|
||||
**他在这些经历中不可避免地会形成这种思想,就需要结合他在厂里受到过的好的影响去与其他经历中一些不好的影响做斗争,以及去改造他的社会关系。比如他认识的流氓无产阶级,我接触他以后就让他断掉了**,和他说那种人和资本家实际上是一个硬币的两面,他也能理解。我们应该有这种自信:我们能把新同志拉到正确的路线上。他说我是他遇到的对他最好的人,他自己会比较冲动,而我比较理智,像他的军师一样,他愿意听我的意见。
|
||||
|
||||
@@ -135,7 +135,7 @@ _思考:_
|
||||
|
||||
- 在提提前面说的护士与我们这些实习生交流的,年轻的护士很多会与我们有共鸣,***除了他们本身工资不高以外,就是面对奇奇怪怪的患者使得她们很崩溃,处理各种就是与她们自身专业不是很相关的事物以及其他的东西***,她们会觉得自己的工资无法匹配这个工作强度,特别是病人居多的科室,这意味输液病人很多,再加上文书什么的,非常忙碌,我们这些实习生同样也是连轴转,还有就是老护士对新护士的压迫,很多时候特别是换输液瓶的时候,都是老护士让新护士去或者让实习生去,或者是做其他的杂活什么的,如果不去的话,可能就是会什么故意针对以及直接找护士长告状诸如此类的,所以说我们实习生和新的年轻护士之间讨论就可以放的开了。
|
||||
|
||||
> 最后的最后,如果让我和她们说马列毛的相关内容,就我那时候的情况而言,可能讲不了多少,不过我个人觉得应该还是说我要与她们的关系更熟悉,然后我自己也能把这种马列毛的分析融入到里面告诉她们,目前我也不能确定有没有其他更好的办法了。
|
||||
- 最后的最后,如果让我和她们说马列毛的相关内容,就我那时候的情况而言,可能讲不了多少,不过我个人觉得应该还是说我要与她们的关系更熟悉,然后我自己也能把这种马列毛的分析融入到里面告诉她们,目前我也不能确定有没有其他更好的办法了。
|
||||
|
||||
|
||||
另:
|
||||
|
||||
@@ -13,11 +13,8 @@
|
||||
在这一期中,工革报好不容易写出来了一个路线式的段落。我们把这一段落摘录如下:
|
||||
|
||||
> 工革报编辑部坚持辩证的、螺旋上升的列宁主义政治报路线。这条路线强调政治报纸作为革命舆论机关和组织成员与群众之间的耦合器作用,通过“报纸——实践——报纸”即“从报纸到报纸”的良性循环,实现革命力量的不断壮大。它既反对机械融工对自发性的迷信,也同时反对把政治报变成脱离实践的孤立任务,而是要把政治报纸与有组织的群众实践紧密结合,形成从理论到群众、从群众到理论的反复飞跃:
|
||||
>
|
||||
> 首先通过政治报纸广泛聚拢先进工人、革命学生和进步知识分子,进行政治揭露和政治灌输,形成初步的理论共识和革命骨干。接着,把这些聚拢起来的人有计划地反向推动到有组织的地方革命实践当中去,然后在工厂、社区等阵地建立基层组织、开展政治教育和斗争锻炼,同时把实践经验和群众创造反哺到报纸中。进而,以扩大了的群众基础和丰富了的实践内容,进一步提升政治报纸的理论深度、报道广度和组织凝聚力,形成从低级到高级、从分散到集中的螺旋发展,最终服务于实质性建党。
|
||||
|
||||
 
|
||||
|
||||
> 我们坚持列宁同志关于从外部灌输社会主义意识的原理,同时强调灌输必须与有组织的群众实践相结合,不能使斗争工作变成少数人的清谈。我们主张通过政治报纸培养出称职的兼职革命家和群众组织,反对任何把自发斗争绝对化或把报纸作用绝对化、极端化的偏差。在当前阶段,重点是把政治报纸作为组织工具和连接线上、线下各部各组织的纽带,吸引先进分子,并把他们反向派往工厂实践,建立地下与地上相结合的基层组织,通过实践检验和丰富报纸内容,形成全国协调统筹的先锋队组织架构和力量,并最终在不断的线下实践斗争当中去促成真正的职业革命家和革命组织(革命党)的形成。
|
||||
>
|
||||
> 以组织为中心,建立起一套卫星式的报刊体系。分层建立起一套分属适用于各个阶段的刊物,例如《工人革命报》、《反修》、《文汇报》等,作为革命舆论机关和组织的耦合器。其内容必须紧密结合中国的无产阶级斗争实际,揭露修正主义政权的本质,传播革命的理论,批判机会主义路线。报纸要坚持独立性,在民主集中制的基础上团结革命力量,但绝不允许变成任何小集团的工具。当前的重点是提高理论质量、扩大发行网络、建立稳定供稿和发行队伍,为实质建党去搭建组织框架,并通过一切方式把先进分子组织起来,反向推动实践与战斗组织建设任务。把通过报纸聚拢的先进分子有计划地通过已经开始行动起来的地方串联小组,来组织起来反向派往工厂、工业区和社区,在有组织的状态下开展群众工作和斗争。不是散漫或自发,而是以革命理论为指导,融入、建立基层小组,培养出工人骨干,进行政治教育和组织锻炼。实践成果要及时反馈,形成“实践出真知、报纸出方向”的良性循环。重点工业区域要实现协调,避免各自为战。
|
||||
@@ -57,7 +54,7 @@
|
||||
而工革报之前联合自由派分子“九”搞出来的统战大纲也明确提到了等级制和经济刺激。
|
||||
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
重复一下我们之前的批判:
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
# 燎原大群路线的实质是林彪主义
|
||||
**编者按:**
|
||||
|
||||
> 这篇文章材料充分,逻辑清晰的论证了大群的林彪主义实质。
|
||||
>
|
||||
>
|
||||
> 我们确定大群所谓的纪律和无产阶级的革命纪律毫无共同之处,其本质是一种庸俗的反毛主义的林彪主义。大群现在已经不是堕入机会主义路线的问题了,其内部被一些德才均不配位的小人和野心分子窃取了领导权,这些人借抽去了革命内容的纪律形式对内实行资产阶级专政,对外搞政治流氓行为,大群正在被这些贪图个人名利的可怜虫带上反革命的道路。
|
||||
>
|
||||
> 我们号召大群内部的同志造他们的反,打倒这些扮演拿破仑的波拿巴小丑。
|
||||
编者按:
|
||||
这篇文章材料充分,逻辑清晰的论证了大群的林彪主义实质。我们确定大群所谓的纪律和无产阶级的革命纪律毫无共同之处,其本质是一种庸俗的反毛主义的林彪主义。大群现在已经不是堕入机会主义路线的问题了,其内部被一些德才均不配位的小人和野心分子窃取了领导权,这些人借抽去了革命内容的纪律形式对内实行资产阶级专政,对外搞政治流氓行为,大群正在被这些贪图个人名利的可怜虫带上反革命的道路。我们号召大群内部的同志造他们的反,打倒这些扮演拿破仑的波拿巴小丑。
|
||||
|
||||
自23年远山高炬等发布黑路线以来,“马列毛主义与革命左翼大群”(燎原/布站)由高呼“到工人中去”的先进组织,一路堕落成一个不断阻碍同志融工、疯狂污蔑推进融工的组织是“无组织”的反革命大群。本文试论大群黑路线的实质,希望深化对大群修正主义本质的探讨,把真理越辩越明,以打击修正主义的根源。
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# 无产阶级纪律必须在群众工作中建设——«左派幼稚病»揭露“野火”反动的纪律路线
|
||||
|
||||
野火说他们学了《共产主义运动中的“左派”幼稚病》(以下简称为《左派幼稚病》),就纪律问题对我们进行了回应,结果却好像根本没看过《左派幼稚病》一样。《左派幼稚病》中已经说明了纪律形成的条件:
|
||||
> 无产阶级革命政党的纪律是靠什么来维持的?是靠什么来检验的?是靠什么来加强的?第一,是靠无产阶级先锋队的觉悟和它对革命的忠诚,是靠它的坚韧不拔、自我牺牲和英雄气概。第二,是靠它善于同最广大的劳动群众,首先是同无产阶级劳动群众,但同样也同非无产阶级劳动群众联系、接近,甚至可以说在某种程度上同他们打成一片。第三,是靠这个先锋队所实行的政治领导正确,靠它的政治战略和策略正确,而最广大的群众根据切身经验也确信其正确。
|
||||
|
||||
>
|
||||
> 无产阶级革命政党的纪律是靠什么来维持的?是靠什么来检验的?是靠什么来加强的?第一,是靠无产阶级先锋队的觉悟和它对革命的忠诚,是靠它的坚韧不拔、自我牺牲和英雄气概。第二,是靠它善于同最广大的劳动群众,首先是同无产阶级劳动群众,但同样也同非无产阶级劳动群众联系、接近,甚至可以说在某种程度上同他们打成一片。第三,是靠这个先锋队所实行的政治领导正确,靠它的政治战略和策略正确,而最广大的群众根据切身经验也确信其正确。一个革命政党,要真正能够成为必将推翻资产阶级并改造整个社会的先进阶级的政党,没有上述条件,就不可能建立起纪律。没有这些条件,建立纪律的企图,就必然会成为空谈,成为漂亮话,成为装模作样。可是另一方面,这些条件又不能一下子就产生。只有经过长期的努力和艰苦的实践才能造成这些条件;正确的革命理论──而理论并不是教条──会使这些条件容易造成,但只有同真正群众性的和真正革命的运动的实践密切地联系起来,这些条件才能最终形成。
|
||||
> 一个革命政党,要真正能够成为必将推翻资产阶级并改造整个社会的先进阶级的政党,没有上述条件,就不可能建立起纪律。没有这些条件,建立纪律的企图,就必然会成为空谈,成为漂亮话,成为装模作样。可是另一方面,这些条件又不能一下子就产生。只有经过长期的努力和艰苦的实践才能造成这些条件;正确的革命理论──而理论并不是教条──会使这些条件容易造成,但只有同真正群众性的和真正革命的运动的实践密切地联系起来,这些条件才能最终形成。
|
||||
|
||||
列宁已经清楚地总结了无产阶级先锋队所需的纪律的三个形成条件。脱离这三点进行工作的话,是无法建立和维持革命政党的纪律的。革命路线的制定,不能不考虑这三个条件,也只有在正确的路线指导下,才能让这些条件在革命者的工作中逐渐形成并成熟。可以看见列宁的纪律路线完全是政治挂帅的。
|
||||
|
||||
@@ -21,12 +21,10 @@
|
||||
|
||||
取得对工人运动的领导权,这个之前已有广泛的经验,如“到工人中去”的经验,以及沈梦雨在广州日弘厂做的工作,这在我们长期扎根的情况下不难做到。而要能够在领导运动的过程中与资产阶级的路线进行斗争,与工人阶级中的自发性进行斗争,没有斗争前已经开展的地下工会中的思想路线工作,是做不到的。
|
||||
|
||||
>
|
||||
> 一个革命政党,要真正能够成为必将推翻资产阶级并改造整个社会的先进阶级的政党,没有上述条件,就不可能建立起纪律。没有这些条件,建立纪律的企图,就必然会成为空谈,成为漂亮话,成为装模作样。
|
||||
|
||||
列宁所列出的这几点,就是为了强调要同志们认识到“发挥与培养自觉性”、“与群众广泛联系”、“坚持政治挂帅”的重要性,而野火不正是这么装模作样地,脱离工人工作等方面来谈组织纪律吗?他们批量产出对厂内工作毫无帮助的水文的纪律,根本不是无产阶级组织的纪律,恰恰是对无产阶级的与群众联系这一纪律的最大破坏。
|
||||
|
||||
>
|
||||
> 可是另一方面,这些条件又不能一下子就产生。只有经过长期的努力和艰苦的实践才能造成这些条件;正确的革命理论──而理论并不是教条──会使这些条件容易造成,但只有同真正群众性的和真正革命的运动的实践密切地联系起来,这些条件才能最终形成。
|
||||
|
||||
我们说我们仍然处于手工业阶段,是因为工业化的组织和自觉的纪律,只有在真正的群众性的革命的运动实践中才能够形成。线上线下要共同工作起来,并不是一件容易的事,这需要融工同志去把线上组织改造成能够一起进行工人工作的组织。像列宁说的,这只有经过长期的努力和艰苦的实践才能实现。当然了,前提是在正确的革命理论,正确的革命路线的指导下的努力和实践。机会主义的路线,不管口号说的多么动听,实际则是在抵触工人群众,拒绝同工人群众的结合。在这种错误路线的指导下,缺乏了与群众性的紧密联系,这些条件难道能顺利形成吗?
|
||||
@@ -40,20 +38,14 @@
|
||||
关于线上工作的纪律性问题,主要的是关于线上工作者与厂内同志的结合的问题,首要的是厂内同志领导线上的问题,而厂内同志要能真正领导线上,是需要经过实践的探索的。正如工人阶级真正占领上层建筑需要通过艰苦的继续革命一样,厂内同志要学会领导线上同志为厂内工作服务,也需要艰苦的实践。
|
||||
|
||||
麒麟在文中提到了线上供稿中的一些积极性的问题,这主要地是供稿是否真正为工人工作服务的问题,供稿如果不为工人工作服务,写作的方向就会不明确,线上同志写作中就不会明确感到自己在走工人革命路线,那自然就难以积极地进行写作。麒麟的老前辈远山,早就就线上组织中的纪律问题提出:
|
||||
|
||||
>
|
||||
> 先扪心自问一下,机会主义者们内部是否存在以下这种情况:布置下去一件任务,但是最后没有人管理,也就没有人完成;或者是某天同志提了一个建议,但是当时有人进行回应,之后就没有人管,提出建议的本人也根本想不起来自己提出过这个建议。
|
||||
|
||||
远山所说的和麒麟所说的几乎是一模一样的。修正主义者往往通过提出一个正确的问题,然后提出修正主义的解法,以此刮起一股风来修正革命路线。为什么会出现远山和麒麟说的,一项建议就连提议的本人也根本想不起来呢?这是因为这个建议没有真正地切中厂内的需求。
|
||||
|
||||
真正的建成革命的纪律性的方法,正如上面我们论述的《左派幼稚病》中的路线,在于真正把线上工作和线下工作结合起来,让线上工作者在工作中真正认同线下的路线,真正感受到是在为线下的工作服务。线上线下的脱节是两方面的原因造成的,一方面是麒麟这样不愿意接受厂内同志领导的,这种相对较少的,更多的是因为厂内同志还没有学会领导线上工作,以及还没有很好地改造线上工作。《工人阶级必须领导一切》中说:
|
||||
|
||||
>
|
||||
> 工人阶级有阶级斗争、生产斗争、科学实验三大革命运动的丰富的实践经验,工人阶级最仇恨一切反社会主义、反毛泽东思想的反革命言行,最痛恨为剥削阶级服务的旧教育制度,最反对某些知识分子破坏国家财产、阻碍斗、批、改的“打内战”行动,最讨厌言行不一的空谈习气和两面派作风。所以,工人阶级群众同无产阶级专政的主要支拄——中国人民解放军的战士相结合,能够最有力地制止一切违反毛主席革命路线的错误倾向,最有效地解决种种所谓“老大难”的问题。知识分子纠缠不休不能解决的矛盾,工人们一到,很快就解决了。
|
||||
|
||||
融工同志是最直接地参与到厂内的三大实践当中的,他们是有最明确的工作需求的,所以融工同志真正需要的东西,那是不可能提出来又忘记的,因为这个需求会在厂内实践中反复反映出来。所以,一切线上和其他群体中的因为缺乏方向而停滞的工作,融工同志一旦发挥领导作用,很快就会有进展。所以,要反对形左实右的唯线下工作论,真正的融工工作应该是同时利用线上和线下的力量来推进厂内工作。正如《工人阶级必须领导一切》所说:
|
||||
|
||||
>
|
||||
> 工人宣传队要有步骤、有计划地到大、中、小学去,到上层建筑各个领域中去,到一切还没有搞好斗、批、改的单位去,…,为了完成这个历史任务,工人阶级必须认真学好毛泽东思想,学习毛主席历来教导的群众路线和调查研究的作风,不断提高自己的政治觉悟,加强革命的纪律性,不断批判工人阶级内部各种资产阶级腐朽作风的侵蚀及影响。
|
||||
|
||||
融工同志应该有步骤有计划地改造线上的一切工作,让线上工作服务于线下工作。在线下领导线上的过程中来让线上了解线下的需求,并且让线上得到工作成果的反馈,这样才能让线上了解线下,实现线下工作和线上工作的充分结合。线上如果没有线下的指导,就不可能为线下服务。工人如果不来领导,那么线上的同志就容易被机会主义分子,被其他阶级领导。
|
||||
@@ -61,6 +53,3 @@
|
||||
野火批判我们没有纪律,然而我们正是依靠同志们自觉的纪律迅速揭露了麒麟这一林彪主义者。在同志们自觉维护的无产阶级专政的震慑下,麒麟连自己批判我们的文章都不敢公开在我们群上发表,还是我们在他叛逃后帮他发布的。在厂内的领导下,同志们继承批林批孔运动的精神,就这位反面教员开展了生动活泼的集体批判、研究和写作。
|
||||
|
||||
我们相信野火中仍然有受蒙蔽的要革命的同志,相信他们学习了《左派幼稚病》后,会意识到脱离厂内工作来建立革命纪律是何等幼稚、野火吹嘘量产对厂内工作毫无用处的水文是多么可笑。要革命的同志们终究会和工农解放社的同志们一起,沿着列宁指引的道路,投身融工与服务融工工作的浪潮中。还是那句老话,厂内广阔天地,大有可为!
|
||||
|
||||
|
||||
|
||||
@@ -5,19 +5,19 @@
|
||||
12 月 27 日,长沙市某省级示范高中爆发了学生抗议活动。据悉,因校方将原定的三天元旦假期突然缩减为两天,引发了学生及部分老师的不满。当天,学生们开始在食堂、年级办公室张贴并传阅抗议檄文和大字报,并进而演变成自发聚集喊楼行动,喊出“誓死力争,还我三休”等口号。最终学生们抗议成功,校方恢复了三天假期。
|
||||
|
||||
**这是学生们打出的大字报**:
|
||||

|
||||

|
||||
|
||||
|
||||

|
||||

|
||||
|
||||
**据传,学校的官僚们也曾试图处理学生**:
|
||||
|
||||

|
||||

|
||||
|
||||
但不管结局如何,学生聚集起来的力量最终还是让官僚们退步了。因为学生们的团结他们也
|
||||
不敢处理学生,并且最终承认了学生们的合法三休权益。学生们事后总结了这场斗争:
|
||||
|
||||

|
||||

|
||||
|
||||
学生们意识到了团结和斗争的作用,他们用大字报等形式把学生的愤怒集中的表现了出来并凝聚为共同的行动。因此,这里的大字报完全起到了集中表述阶级情绪、阶级利益和集中阶级行动作用。同时,大字报等行为和运动本身也推动了整个学生的进步,使原本茫然服从学校秩序和服务官僚资产阶级利益的学生们开始明确的把自身和学校官僚们对立了起来,在自身集体利益和学校官僚利益之间选择了前者。
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
}
|
||||
|
||||
.global h1 {
|
||||
font-size: 3rem;
|
||||
|
||||
line-height: 1.5;
|
||||
}
|
||||
.global h2 {
|
||||
@@ -61,18 +63,39 @@
|
||||
color: white;
|
||||
background-color: red;
|
||||
border: 0.18rem solid red;
|
||||
display: inline-flex;
|
||||
display: block;
|
||||
break-before: page;
|
||||
page-break-before: always;
|
||||
width: fit-content;
|
||||
line-height: 1.5;
|
||||
padding: 0.08em 0.24em;
|
||||
white-space: normal;
|
||||
word-break: break-all;
|
||||
font-family: "ZCOOL QingKe HuangYou", sans-serif;
|
||||
margin: 1rem 1rem 0rem 2rem;
|
||||
margin: 0 1rem 1.5rem 2rem;
|
||||
border-radius: 0.5rem;
|
||||
overflow-wrap: break-word;
|
||||
max-width: 21cm;
|
||||
}
|
||||
|
||||
/* Keep the first article with its column title; separate later articles
|
||||
while allowing their bodies to flow across pages. */
|
||||
.passages {
|
||||
margin: 0 2rem;
|
||||
padding: 0 0 1.5rem;
|
||||
break-inside: auto;
|
||||
page-break-inside: auto;
|
||||
}
|
||||
|
||||
.passages:not(.first-passage) {
|
||||
break-before: page;
|
||||
page-break-before: always;
|
||||
}
|
||||
|
||||
.passages.first-passage > :first-child {
|
||||
margin-block-start: 1.5rem;
|
||||
}
|
||||
|
||||
.index-column page_title {
|
||||
font-size: calc(var(--font-size) + 0.5rem);
|
||||
font-weight: bold;
|
||||
@@ -85,14 +108,95 @@
|
||||
margin: 1rem 0;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Material You-inspired surfaces for Markdown-generated tables. */
|
||||
.global table {
|
||||
width: 100%;
|
||||
margin: 1.5rem 0 2rem;
|
||||
border: 1px solid #c4c7c5;
|
||||
border-radius: 0.75rem;
|
||||
border-spacing: 0;
|
||||
border-collapse: separate;
|
||||
background-color: #fdfbff;
|
||||
color: #1a1b1f;
|
||||
overflow: hidden;
|
||||
break-inside: auto;
|
||||
page-break-inside: auto;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.global table caption {
|
||||
margin-bottom: 0.75rem;
|
||||
color: #454746;
|
||||
font-size: 0.9em;
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.global table thead {
|
||||
display: table-header-group;
|
||||
background-color: #dcefeb;
|
||||
color: #00201f;
|
||||
}
|
||||
|
||||
.global table th,
|
||||
.global table td {
|
||||
padding: 0.75rem 1rem;
|
||||
border-right: 1px solid #c4c7c5;
|
||||
border-bottom: 1px solid #c4c7c5;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.global table th {
|
||||
color: #00504f;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.global table tbody tr:nth-child(even) {
|
||||
background-color: #f3f5f3;
|
||||
}
|
||||
|
||||
.global table tbody tr {
|
||||
break-inside: avoid;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
.global table tr > :last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.global table tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.global table thead tr:first-child th:first-child {
|
||||
border-top-left-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global table thead tr:first-child th:last-child {
|
||||
border-top-right-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global table tbody tr:last-child td:first-child {
|
||||
border-bottom-left-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global table tbody tr:last-child td:last-child {
|
||||
border-bottom-right-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global img {
|
||||
height: 100%;
|
||||
object-fit: scale-down;
|
||||
height: auto;
|
||||
max-width: 100%;
|
||||
max-height: 25cm;
|
||||
border-radius: 12px;
|
||||
border: 4px solid linear-gradient(45deg, #e799b1, #44b144, #2f90ba);
|
||||
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
||||
max-height: 33vh;
|
||||
object-fit: contain;
|
||||
padding: 5px;
|
||||
border: 1px solid #c9d9d5;
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 8px rgba(24, 50, 46, 0.14);
|
||||
display: block;
|
||||
margin: 1rem auto;
|
||||
/* color: transparent; */
|
||||
|
||||
@@ -49,11 +49,23 @@
|
||||
/* Use padding instead of adjacent margins so the article separators remain
|
||||
visible when Chromium fragments the document for printing. */
|
||||
.passages {
|
||||
padding-block: 2.5rem;
|
||||
margin: 0 2rem;
|
||||
padding: 0 0 2.5rem;
|
||||
break-inside: auto;
|
||||
page-break-inside: auto;
|
||||
}
|
||||
|
||||
/* Keep the column title with its first article, but start later articles
|
||||
on a fresh page while allowing each article body to fragment naturally. */
|
||||
.passages:not(.first-passage) {
|
||||
break-before: page;
|
||||
page-break-before: always;
|
||||
}
|
||||
|
||||
.passages.first-passage > :first-child {
|
||||
margin-block-start: 1.5rem;
|
||||
}
|
||||
|
||||
.global h1 {
|
||||
line-height: 4rem;
|
||||
font-family: "HongLei", sans-serif;
|
||||
@@ -84,14 +96,16 @@
|
||||
color: white;
|
||||
background-color: red;
|
||||
border: 0.18rem solid red;
|
||||
display: inline-flex;
|
||||
display: block;
|
||||
break-before: page;
|
||||
page-break-before: always;
|
||||
width: fit-content;
|
||||
line-height: 1.5;
|
||||
padding: 0.08em 0.24em;
|
||||
white-space: normal;
|
||||
word-break: break-all;
|
||||
font-family: "ZCOOL QingKe HuangYou", sans-serif;
|
||||
margin: 4rem 1rem 1rem 2rem;
|
||||
margin: 0 1rem 1.5rem 2rem;
|
||||
border-radius: 0.5rem;
|
||||
overflow-wrap: break-word;
|
||||
max-width: 21cm;
|
||||
@@ -103,13 +117,100 @@
|
||||
padding: 0.5rem 1rem;
|
||||
margin: 1rem 0;
|
||||
color: #666;
|
||||
break-inside: auto;
|
||||
page-break-inside: auto;
|
||||
break-after: auto;
|
||||
page-break-after: auto;
|
||||
}
|
||||
|
||||
/* Material You-inspired table surfaces for Markdown-generated tables. */
|
||||
.global table {
|
||||
width: 100%;
|
||||
margin: 1.5rem 0 2rem;
|
||||
border: 1px solid #c4c7c5;
|
||||
border-radius: 0.75rem;
|
||||
border-spacing: 0;
|
||||
border-collapse: separate;
|
||||
background-color: #fdfbff;
|
||||
color: #1a1b1f;
|
||||
overflow: hidden;
|
||||
break-inside: auto;
|
||||
page-break-inside: auto;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.global table caption {
|
||||
margin-bottom: 0.75rem;
|
||||
color: #454746;
|
||||
font-size: 0.9em;
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.global table thead {
|
||||
display: table-header-group;
|
||||
background-color: #dcefeb;
|
||||
color: #00201f;
|
||||
}
|
||||
|
||||
.global table th,
|
||||
.global table td {
|
||||
padding: 0.75rem 1rem;
|
||||
border-right: 1px solid #c4c7c5;
|
||||
border-bottom: 1px solid #c4c7c5;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.global table th {
|
||||
color: #00504f;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.global table tbody tr:nth-child(even) {
|
||||
background-color: #f3f5f3;
|
||||
}
|
||||
|
||||
.global table tbody tr {
|
||||
break-inside: avoid;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
.global table tr > :last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.global table tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.global table thead tr:first-child th:first-child {
|
||||
border-top-left-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global table thead tr:first-child th:last-child {
|
||||
border-top-right-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global table tbody tr:last-child td:first-child {
|
||||
border-bottom-left-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global table tbody tr:last-child td:last-child {
|
||||
border-bottom-right-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 12px;
|
||||
border: 4px solid linear-gradient(45deg, #e799b1, #44b144, #2f90ba);
|
||||
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
||||
max-height: 33vh;
|
||||
object-fit: contain;
|
||||
padding: 5px;
|
||||
border: 1px solid #c9d9d5;
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 8px rgba(24, 50, 46, 0.14);
|
||||
display: block;
|
||||
margin: 1rem auto;
|
||||
/* color: transparent; */
|
||||
|
||||
@@ -93,6 +93,85 @@
|
||||
border-radius: 22px;
|
||||
border-color: #666;
|
||||
}
|
||||
|
||||
/* Material You-inspired surfaces for Markdown-generated tables. */
|
||||
.global table {
|
||||
width: 100%;
|
||||
margin: 1.5rem 0 2rem;
|
||||
border: 1px solid #c4c7c5;
|
||||
border-radius: 0.75rem;
|
||||
border-spacing: 0;
|
||||
border-collapse: separate;
|
||||
background-color: #fdfbff;
|
||||
color: #1a1b1f;
|
||||
overflow: hidden;
|
||||
break-inside: auto;
|
||||
page-break-inside: auto;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.global table caption {
|
||||
margin-bottom: 0.75rem;
|
||||
color: #454746;
|
||||
font-size: 0.9em;
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.global table thead {
|
||||
display: table-header-group;
|
||||
background-color: #dcefeb;
|
||||
color: #00201f;
|
||||
}
|
||||
|
||||
.global table th,
|
||||
.global table td {
|
||||
padding: 0.75rem 1rem;
|
||||
border-right: 1px solid #c4c7c5;
|
||||
border-bottom: 1px solid #c4c7c5;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.global table th {
|
||||
color: #00504f;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.global table tbody tr:nth-child(even) {
|
||||
background-color: #f3f5f3;
|
||||
}
|
||||
|
||||
.global table tbody tr {
|
||||
break-inside: avoid;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
.global table tr > :last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.global table tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.global table thead tr:first-child th:first-child {
|
||||
border-top-left-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global table thead tr:first-child th:last-child {
|
||||
border-top-right-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global table tbody tr:last-child td:first-child {
|
||||
border-bottom-left-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global table tbody tr:last-child td:last-child {
|
||||
border-bottom-right-radius: 0.75rem;
|
||||
}
|
||||
|
||||
.global img {
|
||||
height: auto;
|
||||
|
||||
|
||||
+7
-1
@@ -94,13 +94,19 @@ deno run -A main.ts --from 26.0.0 generate md
|
||||
# 将每个配置的文章合并导出为 Markdown
|
||||
deno run -A main.ts generate md
|
||||
|
||||
# 导出为 HTML(图片直接内嵌,路径从 md.path 派生)
|
||||
deno run -A main.ts generate html
|
||||
|
||||
# 根据 md.path 导出为纯文本(输出文件名中的 md 会替换为 txt)
|
||||
deno run -A main.ts generate txt
|
||||
|
||||
# 按配置中的 publication 生成 EPUB 3,包含可点击目录
|
||||
# 按配置中的 publication 生成 EPUB 3,包含可点击目录和 EPUB 包内图片
|
||||
deno run -A main.ts generate epub
|
||||
```
|
||||
|
||||
Markdown 和 HTML 导出会将本地图片嵌入为 Base64 data URL。EPUB 不使用 data URL,
|
||||
而是将图片作为 EPUB 包内资源保存并从章节引用,兼容 EPUB 阅读器的资源模型。
|
||||
|
||||
EPUB 默认使用 `md.path` 将扩展名替换为 `.epub`;也可在每个配置中设置
|
||||
`[settings.epub]` 的 `path`、`title`、`author` 和 `language`。每篇文章会拆成独立章节,
|
||||
EPUB 导航目录按出版物排序链接到各章节。
|
||||
|
||||
@@ -131,6 +131,25 @@ export async function generate_md() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function generate_html() {
|
||||
await cacheBeforeGeneration();
|
||||
for (const config of selectedConfigs()) {
|
||||
const builder = new DocuBuilder(
|
||||
config,
|
||||
await createTemplateVariables(args, config, cfg.vars),
|
||||
);
|
||||
builder.with_files_sync(config.journal.from_directory);
|
||||
const html = await builder.as_html_page();
|
||||
const markdownPath = config.md?.path ?? config.markdown_output;
|
||||
if (!markdownPath) {
|
||||
throw new Error("Missing output path in config. Use md.path.");
|
||||
}
|
||||
const htmlPath = markdownPath.replace(/\.md$/i, ".html");
|
||||
await Deno.writeTextFile(htmlPath, html);
|
||||
console.log(`Generated HTML: ${htmlPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function generate_txt() {
|
||||
await cacheBeforeGeneration();
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
generate_epub,
|
||||
generate_html,
|
||||
generate_md,
|
||||
generate_pdf,
|
||||
generate_txt,
|
||||
@@ -35,6 +36,9 @@ export async function match_sub_command_to_function(
|
||||
case "md":
|
||||
await generate_md();
|
||||
break;
|
||||
case "html":
|
||||
await generate_html();
|
||||
break;
|
||||
case "txt":
|
||||
await generate_txt();
|
||||
break;
|
||||
|
||||
+17
-11
@@ -240,28 +240,34 @@ export class EpubBuilder {
|
||||
sourceDir,
|
||||
decodeURIComponent(sourceUrl.split(/[?#]/, 1)[0]),
|
||||
);
|
||||
const assetMarker = sourceUrl.match(/(?:^|\/)assets\/(.+)$/i);
|
||||
const sharedAsset = assetMarker && this.config.asset_base
|
||||
? resolve(this.config.asset_base, assetMarker[1])
|
||||
: undefined;
|
||||
const resolvedAsset = sharedAsset && await Deno.stat(sharedAsset)
|
||||
.then((info) => info.isFile ? sharedAsset : undefined)
|
||||
.catch(() => undefined) || sourceAsset;
|
||||
if (knownTargets.has(sourceAsset)) continue;
|
||||
if (
|
||||
!sourceAsset.startsWith(
|
||||
const localAsset = resolvedAsset.startsWith(
|
||||
`${resolve(this.config.journal.from_directory)}${sep}`,
|
||||
)
|
||||
) continue;
|
||||
) || (sharedAsset != null && resolvedAsset === sharedAsset);
|
||||
if (!localAsset) continue;
|
||||
try {
|
||||
const info = await Deno.stat(sourceAsset);
|
||||
const info = await Deno.stat(resolvedAsset);
|
||||
if (!info.isFile) continue;
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const destination = mediaBySource.get(sourceAsset) ??
|
||||
const destination = mediaBySource.get(resolvedAsset) ??
|
||||
`media/${index}/${media.length + 1}${
|
||||
extname(sourceAsset).toLowerCase()
|
||||
extname(resolvedAsset).toLowerCase()
|
||||
}`;
|
||||
if (!mediaBySource.has(sourceAsset)) {
|
||||
mediaBySource.set(sourceAsset, destination);
|
||||
const ext = extname(sourceAsset).toLowerCase();
|
||||
if (!mediaBySource.has(resolvedAsset)) {
|
||||
mediaBySource.set(resolvedAsset, destination);
|
||||
const ext = extname(resolvedAsset).toLowerCase();
|
||||
media.push({
|
||||
href: destination,
|
||||
bytes: await Deno.readFile(sourceAsset),
|
||||
bytes: await Deno.readFile(resolvedAsset),
|
||||
mime: mediaType(ext),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -79,3 +79,87 @@ Deno.test("uses EPUB output path or a stable default", () => {
|
||||
});
|
||||
assertEquals(builder.outputPath(), "./outputs/book.epub");
|
||||
});
|
||||
|
||||
Deno.test("bundles shared assets referenced by publication articles", async () => {
|
||||
const root = await Deno.makeTempDir();
|
||||
const publication = `${root}/publication`;
|
||||
const templates = `${root}/templates`;
|
||||
const assets = `${root}/assets`;
|
||||
const output = `${root}/shared-assets.epub`;
|
||||
await Deno.mkdir(`${publication}/1::专栏`, { recursive: true });
|
||||
await Deno.mkdir(templates, { recursive: true });
|
||||
await Deno.mkdir(`${assets}/pictures`, { recursive: true });
|
||||
await Deno.writeTextFile(
|
||||
`${publication}/1::专栏/1::文章.md`,
|
||||
"",
|
||||
);
|
||||
const imageBytes = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
|
||||
await Deno.writeFile(`${assets}/pictures/shared.png`, imageBytes);
|
||||
const builder = new EpubBuilder({
|
||||
asset_base: assets,
|
||||
journal: {
|
||||
build_mode: "detached",
|
||||
from_directory: publication,
|
||||
template_directory: templates,
|
||||
},
|
||||
epub: { path: output },
|
||||
}).with_files_sync();
|
||||
|
||||
try {
|
||||
await builder.build();
|
||||
const archive = inspectEpub(await Deno.readFile(output));
|
||||
const chapter = new TextDecoder().decode(
|
||||
archive["EPUB/text/0001-文章.xhtml"],
|
||||
);
|
||||
assertStringIncludes(chapter, "../media/1/1.png");
|
||||
assertEquals(
|
||||
[...archive["EPUB/media/1/1.png"]],
|
||||
[...imageBytes],
|
||||
);
|
||||
} finally {
|
||||
await Deno.remove(root, { recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("packages shared assets directory images as EPUB resources", async () => {
|
||||
const root = await Deno.makeTempDir();
|
||||
const publication = `${root}/publication`;
|
||||
const templates = `${root}/templates`;
|
||||
const assets = `${root}/assets`;
|
||||
const output = `${root}/shared-assets.epub`;
|
||||
await Deno.mkdir(`${publication}/1::专栏`, { recursive: true });
|
||||
await Deno.mkdir(templates, { recursive: true });
|
||||
await Deno.mkdir(`${assets}/pictures`, { recursive: true });
|
||||
await Deno.writeTextFile(
|
||||
`${publication}/1::专栏/1::文章.md`,
|
||||
"",
|
||||
);
|
||||
const imageBytes = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
|
||||
await Deno.writeFile(`${assets}/pictures/shared.png`, imageBytes);
|
||||
const builder = new EpubBuilder({
|
||||
asset_base: assets,
|
||||
journal: {
|
||||
build_mode: "detached",
|
||||
from_directory: publication,
|
||||
template_directory: templates,
|
||||
identifier: "urn:test:shared-assets",
|
||||
},
|
||||
epub: { path: output },
|
||||
}).with_files_sync();
|
||||
|
||||
try {
|
||||
await builder.build();
|
||||
const zip = inspectEpub(await Deno.readFile(output));
|
||||
const chapter = new TextDecoder().decode(
|
||||
zip["EPUB/text/0001-文章.xhtml"],
|
||||
);
|
||||
assertStringIncludes(chapter, "../media/1/1.png");
|
||||
assertEquals(zip["EPUB/media/1/1.png"], imageBytes);
|
||||
assertStringIncludes(
|
||||
new TextDecoder().decode(zip["EPUB/content.opf"]),
|
||||
'media/1/1.png" media-type="image/png"',
|
||||
);
|
||||
} finally {
|
||||
await Deno.remove(root, { recursive: true });
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { DocuBuilder } from "./docu_builder.ts";
|
||||
import { md } from "../mdit/md.ts";
|
||||
|
||||
Deno.test("PDF rendering loads relative assets from configured file base", async () => {
|
||||
const chromiumPath = Deno.env.get("CHROMIUM_PATH");
|
||||
@@ -24,3 +25,65 @@ Deno.test("PDF rendering loads relative assets from configured file base", async
|
||||
assertEquals((await Deno.stat(pdfPath)).size > 0, true);
|
||||
await Deno.remove(pdfPath);
|
||||
});
|
||||
|
||||
Deno.test("PDF rendering waits for remote Markdown images", async () => {
|
||||
if (!Deno.env.get("CHROMIUM_PATH")) return;
|
||||
|
||||
const builder = new DocuBuilder({
|
||||
asset_base: "../../assets",
|
||||
journal: { build_js_script: false },
|
||||
});
|
||||
const pdfPath = await Deno.makeTempFile({ suffix: ".pdf" });
|
||||
await builder.with_browser();
|
||||
try {
|
||||
await builder.build_as_pdf({ path: pdfPath, format: "A4" }, [
|
||||
'<img src="https://imgbed.cmlmuf.org/i/2026/08/31/wd5mok.jpg" alt="Remote asset">',
|
||||
]);
|
||||
} finally {
|
||||
await builder.close_browser();
|
||||
}
|
||||
assertEquals((await Deno.stat(pdfPath)).size > 0, true);
|
||||
await Deno.remove(pdfPath);
|
||||
});
|
||||
|
||||
Deno.test("PDF rendering embeds publication-relative asset images", async () => {
|
||||
if (!Deno.env.get("CHROMIUM_PATH")) return;
|
||||
|
||||
const builder = new DocuBuilder({
|
||||
asset_base: "../../assets",
|
||||
journal: { build_js_script: false },
|
||||
});
|
||||
const resolvedHtml = (builder as any).resolveLocalAssetImages(
|
||||
'<img src="../../../assets/pictures/rsf.png">' +
|
||||
'<img src="https://example.test/remote.png">',
|
||||
);
|
||||
assertEquals(
|
||||
resolvedHtml.includes('src="data:image/png;base64,'),
|
||||
true,
|
||||
);
|
||||
assertEquals(
|
||||
resolvedHtml.includes('src="https://example.test/remote.png"'),
|
||||
true,
|
||||
);
|
||||
assertEquals(resolvedHtml.includes('loading="eager"'), false);
|
||||
const markdownHtml = md.render(
|
||||
"",
|
||||
);
|
||||
const eagerHtml = (builder as any).resolveLocalAssetImages(markdownHtml);
|
||||
assertEquals(eagerHtml.includes('loading="lazy"'), false);
|
||||
assertEquals(eagerHtml.includes('loading="eager"'), true);
|
||||
const pdfPath = await Deno.makeTempFile({ suffix: ".pdf" });
|
||||
await builder.with_browser();
|
||||
try {
|
||||
await builder.build_as_pdf({ path: pdfPath, format: "A4" }, [
|
||||
(builder as any).resolveLocalAssetImages(
|
||||
'<img src="../../../assets/pictures/26.11.0_pictures/ef1be4ca769fc52e513e69e1-129si8u.png" alt="Publication asset">',
|
||||
),
|
||||
]);
|
||||
} finally {
|
||||
await builder.close_browser();
|
||||
}
|
||||
const pdfText = new TextDecoder().decode(await Deno.readFile(pdfPath));
|
||||
assertEquals(pdfText.includes("/Subtype /Image"), true);
|
||||
await Deno.remove(pdfPath);
|
||||
});
|
||||
@@ -81,6 +81,49 @@ export class DocuBuilder {
|
||||
.trim();
|
||||
}
|
||||
|
||||
private resolveLocalAssetImages(html: string): string {
|
||||
const eagerHtml = html.replace(
|
||||
/(<img\b[^>]*\sloading=["'])lazy(["'])/gi,
|
||||
"$1eager$2",
|
||||
);
|
||||
return eagerHtml.replace(
|
||||
/(<img\b[^>]*\bsrc=["'])([^"']+)(["'])/gi,
|
||||
(_match, prefix: string, source: string, suffix: string) => {
|
||||
const assetMarker = source.match(/(?:^|\/)assets\/(.+)$/i);
|
||||
if (/^[a-z][a-z\d+.-]*:/i.test(source)) {
|
||||
return `${prefix}${source}${suffix}`;
|
||||
}
|
||||
try {
|
||||
const assetUrl = assetMarker
|
||||
? new URL(assetMarker[1], this.assetBaseHref)
|
||||
: new URL(source, this.assetBaseHref);
|
||||
const bytes = Deno.readFileSync(assetUrl);
|
||||
let binary = "";
|
||||
for (let offset = 0; offset < bytes.length; offset += 0x8000) {
|
||||
binary += String.fromCharCode(
|
||||
...bytes.subarray(offset, offset + 0x8000),
|
||||
);
|
||||
}
|
||||
const extension = assetUrl
|
||||
.pathname.split(".").at(-1)?.toLowerCase();
|
||||
const mime = extension === "png"
|
||||
? "image/png"
|
||||
: extension === "webp"
|
||||
? "image/webp"
|
||||
: extension === "gif"
|
||||
? "image/gif"
|
||||
: "image/jpeg";
|
||||
return `${prefix}data:${mime};base64,${btoa(binary)}${suffix}`;
|
||||
} catch (error) {
|
||||
console.warn(`Could not embed local image ${source}: ${error}`);
|
||||
return `${prefix}${
|
||||
assetMarker ? `${this.assetBaseHref}${assetMarker[1]}` : source
|
||||
}${suffix}`;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async as_markdown() {
|
||||
const turndownService = new TurndownService();
|
||||
const html_page = await this.as_html_page();
|
||||
@@ -125,7 +168,9 @@ export class DocuBuilder {
|
||||
);
|
||||
colume.pfiles.forEach((pfile) => {
|
||||
const passageId = id++;
|
||||
const html = md.render(this.render(pfile.content, {
|
||||
const firstPassageClass = c_id === 1 ? " first-passage" : "";
|
||||
const html = this.resolveLocalAssetImages(
|
||||
md.render(this.render(pfile.content, {
|
||||
document: {
|
||||
title: pfile.meta.title,
|
||||
index: pfile.meta.index,
|
||||
@@ -135,7 +180,8 @@ export class DocuBuilder {
|
||||
name: colume.name,
|
||||
index: colume.index,
|
||||
},
|
||||
}));
|
||||
})),
|
||||
);
|
||||
let foundHeading = false;
|
||||
const indexedHtml = html.replace(
|
||||
/<h1(\b[^>]*)>([\s\S]*?)<\/h1>/i,
|
||||
@@ -151,7 +197,7 @@ export class DocuBuilder {
|
||||
);
|
||||
const printableHtml = markedHtml;
|
||||
this.pages.push(
|
||||
`<div class="global c${c_id++} passages" id="page-${passageId}">${printableHtml}</div>`,
|
||||
`<div class="global c${c_id++} passages${firstPassageClass}" id="page-${passageId}">${printableHtml}</div>`,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -266,7 +312,53 @@ return document?.documentElement?.outerHTML ?? html;`,
|
||||
const htmlPath = await Deno.makeTempFile({ suffix: ".html" });
|
||||
try {
|
||||
await Deno.writeTextFile(htmlPath, htmlWithBase);
|
||||
await page.goto(pathToFileURL(htmlPath).href, { timeout: 120000 });
|
||||
await page.goto(pathToFileURL(htmlPath).href, {
|
||||
timeout: 120000,
|
||||
waitUntil: "domcontentloaded",
|
||||
});
|
||||
|
||||
// `page.goto(..., { waitUntil: "load" })` does not guarantee that
|
||||
// every image has finished decoding before printing. Wait for each
|
||||
// image explicitly so remote Markdown images are included in the PDF.
|
||||
const failedImages = await page.evaluate(async () => {
|
||||
// The project is type-checked without the DOM library; these values
|
||||
// live in Chromium's page context, not in the Deno runtime.
|
||||
const pageDocument = (globalThis as any).document;
|
||||
const images = Array.from(pageDocument.images) as any[];
|
||||
const timedOutImages = await Promise.all(images.map((image) => {
|
||||
if (image.complete) return Promise.resolve(false);
|
||||
return new Promise<boolean>((resolve) => {
|
||||
let settled = false;
|
||||
const finish = () => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timeout);
|
||||
resolve(false);
|
||||
};
|
||||
const timeout = setTimeout(() => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
resolve(true);
|
||||
}, 15000);
|
||||
image.addEventListener("load", finish, { once: true });
|
||||
image.addEventListener("error", finish, { once: true });
|
||||
});
|
||||
}));
|
||||
const failed = images
|
||||
.filter((image) => !image.naturalWidth)
|
||||
.map((image) => image.currentSrc || image.src);
|
||||
return failed.length > 0
|
||||
? failed
|
||||
: images.filter((_image, index) => timedOutImages[index])
|
||||
.map((image) => image.currentSrc || image.src);
|
||||
});
|
||||
if (failedImages.length > 0) {
|
||||
console.warn(
|
||||
`Continuing PDF generation with ${failedImages.length} image(s) not loaded within 15 seconds: ${
|
||||
failedImages.join(", ")
|
||||
}`,
|
||||
);
|
||||
}
|
||||
|
||||
await page.pdf(pw_config);
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user