l1xnan / obsidian-better-export-pdf

Obsidian PDF export enhancement plugin
MIT License
311 stars 18 forks source link

Paragraph Indent #213

Closed Least-Action-Frank closed 4 months ago

Least-Action-Frank commented 4 months ago

By use one snippet (refer to code hereinafter) Paragraph Indent for Chinses is relized both in edit and reading. But export PDF, Paragraph Indent is missing in generated PDF.

/ === 段落-首行缩进2个字符 By Linzeal 2024/2/1更新 yuanling 2024/03/30 改=== /

/ 也包括段落中每个回车换行后的首行缩进 /

:is( .markdown-source-view .cm-line:not(:is(:has(>.cm-hmd-frontmatter,>br),.HyperMD-header,.HyperMD-list-line,.HyperMD-quote,table .cm-line)), / 编辑模式 / .markdown-rendered :not(:is(blockquote)) > / 阅读模式 text-indent不支持each-line的办法 / ){ text-indent: 2em !important; }

/若支持each-line参数则用这个即可,更为简单,就无需下面的修正 /

/ 阅读模式下对每个回车换行后的首行缩进的修正 / /需要 contextual tyopgraphy 插件/

.markdown-rendered div[class*="el-p"]:not(blockquote) > p { text-indent: 2em; }

.markdown-rendered div[class="el-p"]:not(blockquote) > p>br { content:''; white-space:pre; } .markdown-rendered div[class="el-p"]:not(blockquote) > p>br::after { content:'\000A\2004\2004\2003'; }

/ === CSS代码结束 === /

l1xnan commented 4 months ago

官方的导出PDF功能是否生效?

Least-Action-Frank commented 4 months ago

官方导出功能正常,但也是没有体现段首的缩进。

Least-Action-Frank commented 4 months ago

这是Obsidian编辑区及生成的PDF文件的截图 捕获1 捕获2

l1xnan commented 4 months ago

是不是预览模式也没有首行缩进呀? 我看官方导出的 PDF 也没有首行缩进,当前插件底层实现是和官方一致的,所以效果也一样。是不是上游插件对这个场景适配有问题?

Least-Action-Frank commented 4 months ago

是的,预览模式也没有首行缩进。应该是您分析的原因造成的,可由于我没有这方面的知识,不是如何解决。方便的话能否分享一点有助于解决这种问题的知识文档。 非常感谢耐心的帮助。

l1xnan commented 4 months ago

只需要如下设置即可:

.markdown-rendered p {
  text-indent: 2rem;
}

只是这样设置命中范围比较广,有些场景你可能不想设置首行缩进,如 Callout 块中的段落,这时候就需要你逐步完善 css 选择器:

.markdown-rendered .callout p {
  text-indent: 0;
}

或者反向的你先精确限制是否首行缩进,逐步完善你的精确场景。 如果在插件层面实现的话,可以按照 ast 解析出来的 section 处理会好一点,不用陷入到繁琐的 css 选择器中。

Least-Action-Frank commented 4 months ago

收到,感谢如此细致的解答。