Ruoshan's jiffies

About Archive

Jekyll中markdown中文显示行尾空格

On 17 Jun 2013, By Ruoshan Huang

markdown获得的<p>的内容是把换行直接换为空格了,英文没问题,但是中文就有很多不必要的空格。

查到的解决方法是这个链接

如链接的文章所说,这个在github page中不能用,因为gh不启用plugin。先写个脚本对markdown做处理再提交就OK了。具体的脚本如下,使用方法(ruby cn_markdown.rb *.md):

#!/usr/bin/env ruby
# encoding: UTF-8
# preprocessing the text for markdown writen in Chinese

han = '\p{Han}|[,。?;:‘’“”、!……()]'
ChineseRegex = /(#{han}) *\n *(#{han})/m

ARGV.each do |fn|
    lines = ''
    File.open(fn,'r') do |file|
        lines = file.gets(nil)
        lines.gsub!(ChineseRegex,'\1\2')
    end
    File.open(fn,'w') do |file|
        file.write(lines)
    end
end