diff --git a/heti-addon.js b/heti-addon.js index 947b9f2..dc7d84c 100644 --- a/heti-addon.js +++ b/heti-addon.js @@ -680,6 +680,9 @@ const REG_BD_CLOSE = `」』)》〉】〗〕]}`; const REG_BD_START = `${REG_BD_OPEN}${REG_BD_CLOSE}`; const REG_BD_END = `${REG_BD_STOP}${REG_BD_OPEN}${REG_BD_CLOSE}`; + const REG_BD_HALF_OPEN = `“‘`; + const REG_BD_HALF_CLOSE = `”’`; + const REG_BD_HALF_START = `${REG_BD_HALF_OPEN}${REG_BD_HALF_CLOSE}`; class Heti { constructor (rootSelector) { @@ -754,6 +757,13 @@ replace: portion => getWrapper('heti-adjacent', 'heti-adjacent-quarter', portion.text), offset: this.offsetWidth, })); + + // 使用弯引号的情况下,在停顿符号接弯引号(如「。“」)或弯引号接全角开引号(如“《」)时,间距缩进调整到四分之一 + findAndReplaceDOMText($$elm, Object.assign({}, commonConfig, { + find: new RegExp(`([${REG_BD_STOP}])(?=[${REG_BD_HALF_START}])|([${REG_BD_HALF_OPEN}])(?=[${REG_BD_OPEN}])`,'g'), + replace: portion => getWrapper('heti-adjacent', 'heti-adjacent-quarter', portion.text), + offset: this.offsetWidth, + })); } autoSpacing () { diff --git a/heti.css b/heti.css index 09aced6..d9c95be 100644 --- a/heti.css +++ b/heti.css @@ -685,6 +685,10 @@ text-align: start; } +.heti--vertical q { + quotes: "「" "」" "『" "』"; +} + .heti--ancient, .heti--poetry { font-family: "Times New Roman", times, "Heti Song", serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; } diff --git a/index.html b/index.html index 4ebce39..65ae70e 100644 --- a/index.html +++ b/index.html @@ -23,14 +23,13 @@
项目源文件:https://github.com/sivan/heti,生产文件已同步至unpkg.com。使用方法如下:
+项目地址:https://github.com/sivan/heti,使用方法如下:
</head>
标签前中引入heti.css
样式文件:
@@ -77,7 +76,7 @@
<article class="entry heti">
<h1>我的世界观</h1>
- <p>有钱人的生活就是这么朴实无华,且枯燥</p>
+ <p>有钱人的生活就是这么朴实无华,且枯燥。</p>
……
</article>
本页面全页应用了赫蹏样式,所见即所得。下面是内置的多种排版效果演示。
+ +为容器元素<div class="heti">
添加名为heti--ancient
的class即可实现古文版式:
<div class="heti heti--ancient">...</div>
+ 先帝创业未半而中道崩殂,今天下三分,益州疲弊,此诚危急存亡之秋也。然侍卫之臣不懈于内,忠志之士忘身于外者,盖追先帝之殊遇,欲报之于陛下也。诚宜开张圣听,以光先帝遗德,恢弘志士之气,不宜妄自菲薄,引喻失义,以塞忠谏之路也。
@@ -107,10 +113,41 @@ +<div class="heti">
添加名为heti--poetry
的class实现诗词版式:
+ <div class="heti heti--poetry">
+ <h2>九月九日忆山东兄弟<span class="heti-meta heti-small">[唐]<abbr title="号摩诘居士">王维</abbr></span></h2>
+ <p class="heti-x-large">
+ 独在异乡为异客<span class="heti-hang">,</span><br>
+ 每逢佳节倍思亲<span class="heti-hang">。</span><br>
+ 遥知兄弟登高处<span class="heti-hang">,</span><br>
+ 遍插茱萸少一人<span class="heti-hang">。</span>
+ </p>
+</div>
+ <div class="heti heti--ancient">
中,为诗句添加名为heti-verse
的class可以将其居中显示:
+ <div class="heti heti--ancient">
+ <h2>一剪梅·红藕香残玉簟秋<span class="heti-meta heti-small">[宋]<abbr title="号易安居士">李清照</abbr></span></h2>
+ <p class="heti-verse heti-x-large">
+ 红藕香残玉簟秋。轻解罗裳,独上兰舟<span class="heti-hang">。</span><br>
+ 云中谁寄锦书来,雁字回时,月满西楼<span class="heti-hang">。</span><br>
+ 花自飘零水自流。一种相思,两处闲愁<span class="heti-hang">。</span><br>
+ 此情无计可消除,才下眉头,却上心头<span class="heti-hang">。</span>
+ </p>
+</div>
+ <span class="heti-hang">
、元信息<span class="heti-meta heti-small">
来丰富展示效果。
红藕香残玉簟秋。轻解罗裳,独上兰舟。
@@ -120,7 +157,7 @@
李白乘舟将欲行,
@@ -132,10 +169,16 @@
+
为容器元素<div class="heti">
添加名为heti--annotation
的class后,搭配<ruby>
元素即可实现整齐的行间注效果:
<div class="heti heti--annotation">...</div>
+ 吾生也有涯,而知也无涯。以有涯随无涯,殆已!已而为知者,殆而已矣!为善无近名,为恶无近刑。缘督以为经,可以保身,可以全生,可以养亲,可以尽年。
@@ -147,26 +190,11 @@ -There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain...
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
-Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
-The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
-赫蹏预置了多种多栏布局类,可以按栏数或每栏行宽进行设置。
为容器元素添加名为heti--columns-2
的class即可实现双栏排版。
为容器元素<div class="heti">
添加名为heti--columns-2
的class即可实现双栏排版:
<div class="heti heti--columns-2">...</div>
赫蹏预置了传统的竖排(直排)方向排版,同样贴合栅格。
为容器元素添加名为heti--vertical
的class即可实现竖排布局。
为容器元素<div class="heti">
添加名为heti--vertical
的class即可实现竖排布局:
<div class="heti heti--vertical">...</div>
There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain...
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
+The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
+赫蹏项目的初衷很简单:它不作为一个CSS Reset出现,而是根据通行的中文排版规范,对网页正文区域进行排版样式增强。在部分CSS特性尚未有浏览器支持前,可通过JavaScript实现部分补充(非必要)。
-美化中文方块字排版,作用范围是网页中的文章区域(含标题、正文、元信息等),不包含网页导航、表单、侧边栏等区域(它们也不需要这套格式排版)。
-使用heti.css
时建议搭配良好的中文书写习惯,即:使用正确的HTML标签(可参考后面的标签示例表)、正确的引号、中文全角标点等。使用Markdown书写文章将助你一臂之力。
赫蹏项目的初衷很简单:它不作为一个CSS Reset出现,而是根据通行的中文排版规范,对网页正文区域进行排版样式增强。在部分CSS特性尚未有浏览器支持前,可通过JavaScript实现功能补充。
参考《中文排版需求[2]》中描述的常用书籍排版字体,赫蹏提供了黑体、宋体和传统三种字体风格,前两者分别对应无衬线、衬线字体族。文字默认采用16px作为标准字号。在标题等文字较大的情况下,会适当地增加字间距以便获得更好地可读性。
标题 | -黑体 | -宋体 | +黑体 | +宋体 | 楷体 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
正文 | -黑体 | -宋体 | 宋体 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
引用 | -黑体 | -宋体 | 楷体 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
强调 | -黑体 | -宋体 | 宋体 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
对话 | -黑体 | -宋体 | 楷体 |
图例 |
黑体 |
- 宋体 |
- 黑体 |
|
@@ -327,8 +359,6 @@
表头 |
黑体 |
- 宋体 |
- 黑体 |
|
目前支持的功能有: +
效果演示: +
开源协议#「赫蹏」遵循MIT协议开源。 @@ -580,7 +622,7 @@ $$article.className = ['article', 'heti', e.target.value].join(' ') }) - const heti = new Heti() + const heti = new Heti('.article') heti.autoSpacing() |