我正在使用customfilter模块使用Drupal的asciidoc语法为文本创建自定义过滤器。我将它括在[asciidoc] [/ asciidoc]标签中,当我通过asciidoctor
命令运行它时,输出被包含在<div class="paragraph"><p>
标签中。
像我这样使用[asciidoc]标签格式化html链接的输出就像这样。
On the markup side Drupal's contrib `markdown` filter has been somewhat iffy,
and so has the `bbcode` filter. Looking around for other more compact documenting
systems led me to the https://asciidoc.org[Asciidoc] utility and its more
advanced brother https://asciidoctor.org[Asciidoctor]. In combination with another
Drupal module called https://drupal.org/project/customfilter[customfilter] which
makes it easy to create your own filters, I think I have hit on a combination
of modules which allow me as much freedom and fine control on my pages as I want.
<div class="paragraph">
<p>On the markup side Drupal’s contrib <code>markdown</code> filter has been somewhat iffy,
and so has the <code>bbcode</code> filter. Looking around for other more compact documenting
systems led me to the <a href="https://asciidoc.org">Asciidoc</a> utility and its more
advanced brother <a href="https://asciidoctor.org">Asciidoctor</a>. In combination with another
Drupal module called <a href="https://drupal.org/project/customfilter">customfilter</a> which
makes it easy to create your own filters, I think I have hit on a combination
of modules which allow me as much freedom and fine control on my pages as I want.</p>
</div>
是否有一些PHP函数可以将字符串HTML和一组封闭标记转换为字符串,并返回它们包含的内部HTML?或者也许是一些可以匹配标签之间部分的正则表达式?
这是所需的输出
On the markup side Drupal’s contrib <code>markdown</code> filter has been somewhat iffy,
and so has the <code>bbcode</code> filter. Looking around for other more compact documenting
systems led me to the <a href="https://asciidoc.org">Asciidoc</a> utility and its more
advanced brother <a href="https://asciidoctor.org">Asciidoctor</a>. In combination with another
Drupal module called <a href="https://drupal.org/project/customfilter">customfilter</a> which
makes it easy to create your own filters, I think I have hit on a combination
of modules which allow me as much freedom and fine control on my pages as I want.
我问了一个相关的问题,是否可以配置asciidoc以避免将输出括在<div class="paragraph"><p>...</p></div>
- Does asciidoctor have a setting to remove the <paragraph> and <p> tags from the source it outputs?
答案 0 :(得分:1)
通过纯PHP,你可以使用我不建议使用的DOMDocument
,因为它很慢,你会在跟踪错误时遇到麻烦等等。出于同样的原因,我不打算更多地解释这个对象。只是来自官方网站的链接:
注意:我个人更喜欢在处理大型文本时使用DomDocument
,例如我曾经阅读整个页面并逐个获取所有元素,这几乎不可能使用正则表达式。在那种情况下,我使用了DomDocument
。
让我们回到你的主题。您的示例显示您没有解析大块,因此我建议您使用Regex
。
preg_match_all( '/<p>(?P<content>.*?)<\/p>/s' ,$text, $ref );
var_dump($ref['content']);
以上正则表达式为您提供了所有元素beetwen p
tag。
您可以使用它并制作一个新的:
preg_match_all( '/<div class="paragraph">\s<p>(?P<content>.*?)<\/*p>\s<\/*div>/' ,$text, $ref );
它为您提供div标签之间的所有内容(标签可能具有任何属性)。
另请参阅以下有关正则表达式的链接
祝你好运