我有一个Rails站点,其中的内容是用markdown编写的.我希望显示每个片段,并带有"阅读更多..."链接.
我该怎么做?简单地截断原始文本将不起作用,例如..
>> "This is an [example](http://example.com)"[0..25]
=> "This is an [example](http:"
Run Code Online (Sandbox Code Playgroud)
理想情况下,我希望允许作者(可选)插入标记以指定要用作"片段"的内容,如果不是,则需要250个单词,并附加"..." - 例如..
This article is an example of something or other.
This segment will be used as the snippet on the index page.
^^^^^^^^^^^^^^^
This text will be visible once clicking the "Read more.." link
Run Code Online (Sandbox Code Playgroud)
标记可以被认为是EOF标记(在显示完整文档时可以忽略)
我正在使用maruku进行Markdown处理(RedCloth非常偏向于Textile,BlueCloth是非常错误的,我想要一个本地Ruby解析器,它排除了peg-markdown和RDiscount)
或者(因为无论如何将Markdown翻译成HTML)正确地截断HTML是一种选择 - 尽管最好不要markdown()整个文档,只是为了获得前几行.
所以,我能想到的选项是(按照优先顺序)..