PHP Markdown 将最后一块内容标记为 h3

发布于 2024-11-15 12:54:44 字数 3324 浏览 3 评论 0原文

我使用 PHP Markdown(版本 1.0.1n,2009 年 10 月更新)来显示文本以 Markdown 格式保存到数据库。我遇到了一个奇怪的问题,它将每个条目的最后一块标记为 H3。但是,当我搜索 markdown.php 文件时,没有任何 H3 实例。

以下是我的数据库中的两段文本:

Since its launch, major CPG brands, endemic as well as non-endemic, have flocked to retail websites to reach consumers deep in the purchase funnel through shopping media. In this session, you will hear about:

- The prioritization of shopping media for CPG brands.

- A case study of brands on Target.com on how this retailer (and others) have introduced a new channel for brand marketers to engage consumers where they are making the majority of purchase decisions: online.

- How CPG brands are leveraging real-time data from shopping media to capture consumer insights and market trends.

在这一段中,它正确地标记了 LI 项目,但在最终的 LI 中,它将实际文本标记为 H3。

Beyond the actual money she saves, this consumer is both empowered and psychologically gratified by getting the best value on her everyday purchases. It is essential for both marketers and retailers to focus on what motivates and activates this consumer. 

Diane Oshin will share insights on what influences her shopping behavior and then identify specific tools that activate her to buy.

在这个例子中,以 Diane Oshin 开头的整个段落都被标记为 H3。

这是真正奇怪的事情:当我查看源代码时,它们都被正确标记;只有在使用 Inspect Element 时我才能看到 H3。然而,在实际显示中很明显,H3标签正在被应用:

示例1 示例 1

示例 2 example 2

有人可以帮我吗?

更新

根据下面的评论,我查找了 H 标签的实例。我找到了这些函数,但不知道这是否是导致问题的原因。它们是整个文件中唯一似乎正在创建任何类型的标头标记的位置。

function doHeaders($text) {
        # Setext-style headers:
        #     Header 1
        #     ========
        #  
        #     Header 2
        #     --------
        #
        $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx',
            array(&$this, '_doHeaders_callback_setext'), $text);

        # atx-style headers:
        #   # Header 1
        #   ## Header 2
        #   ## Header 2 with closing hashes ##
        #   ...
        #   ###### Header 6
        #
        $text = preg_replace_callback('{
                ^(\#{1,6})  # $1 = string of #\'s
                [ ]*
                (.+?)       # $2 = Header text
                [ ]*
                \#*         # optional closing #\'s (not counted)
                \n+
            }xm',
            array(&$this, '_doHeaders_callback_atx'), $text);

        return $text;
    }
    function _doHeaders_callback_setext($matches) {
        # Terrible hack to check we haven't found an empty list item.
        if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1]))
            return $matches[0];

        $level = $matches[2]{0} == '=' ? 1 : 2;
        $block = "<h$level>".$this->runSpanGamut($matches[1])."</h$level>";
        return "\n" . $this->hashBlock($block) . "\n\n";
    }
    function _doHeaders_callback_atx($matches) {
        $level = strlen($matches[1]);
        $block = "<h$level>".$this->runSpanGamut($matches[2])."</h$level>";
        return "\n" . $this->hashBlock($block) . "\n\n";
    }

I'm using PHP Markdown (version 1.0.1n, updated October 2009) to display text saved to a database in markdown format. I'm running into a strange issue where it's tagging the last chunk of every entry as an H3. When I search the markdown.php file, though, there isn't a single instance of H3.

Here are two pieces of text from my database:

Since its launch, major CPG brands, endemic as well as non-endemic, have flocked to retail websites to reach consumers deep in the purchase funnel through shopping media. In this session, you will hear about:

- The prioritization of shopping media for CPG brands.

- A case study of brands on Target.com on how this retailer (and others) have introduced a new channel for brand marketers to engage consumers where they are making the majority of purchase decisions: online.

- How CPG brands are leveraging real-time data from shopping media to capture consumer insights and market trends.

In this one, it is tagging the LI items correctly, but inside the final LI it's tagging the actual text as H3.

Beyond the actual money she saves, this consumer is both empowered and psychologically gratified by getting the best value on her everyday purchases. It is essential for both marketers and retailers to focus on what motivates and activates this consumer. 

Diane Oshin will share insights on what influences her shopping behavior and then identify specific tools that activate her to buy.

In this one, the entire paragraph starting with Diane Oshin is tagged as an H3.

Here's the really odd thing: when I do a view source, both of them are tagged correctly; it's only when using Inspect Element that I see the H3. However, it's obvious in the actual display that the H3 tag is being applied:

example 1
example 1

example 2
example 2

Can anyone help me out?

update

Per a comment below, I looked for instances of H tags. I found these functions, but don't know if this is what could be causing the issue or not. They are the only place in the entire file that appears to be creating a header tag of any kind.

function doHeaders($text) {
        # Setext-style headers:
        #     Header 1
        #     ========
        #  
        #     Header 2
        #     --------
        #
        $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx',
            array(&$this, '_doHeaders_callback_setext'), $text);

        # atx-style headers:
        #   # Header 1
        #   ## Header 2
        #   ## Header 2 with closing hashes ##
        #   ...
        #   ###### Header 6
        #
        $text = preg_replace_callback('{
                ^(\#{1,6})  # $1 = string of #\'s
                [ ]*
                (.+?)       # $2 = Header text
                [ ]*
                \#*         # optional closing #\'s (not counted)
                \n+
            }xm',
            array(&$this, '_doHeaders_callback_atx'), $text);

        return $text;
    }
    function _doHeaders_callback_setext($matches) {
        # Terrible hack to check we haven't found an empty list item.
        if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1]))
            return $matches[0];

        $level = $matches[2]{0} == '=' ? 1 : 2;
        $block = "<h$level>".$this->runSpanGamut($matches[1])."</h$level>";
        return "\n" . $this->hashBlock($block) . "\n\n";
    }
    function _doHeaders_callback_atx($matches) {
        $level = strlen($matches[1]);
        $block = "<h$level>".$this->runSpanGamut($matches[2])."</h$level>";
        return "\n" . $this->hashBlock($block) . "\n\n";
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随心而道 2024-11-22 12:54:44

我无法用您提供的版本重现您所描述的内容:

<?php
include(__DIR__.'/php-markdown/markdown.php');


$testText = 'Since its launch, major CPG brands, endemic as well as non-endemic, have flocked to retail websites to reach consumers deep in the purchase funnel through shopping media. In this session, you will hear about:

- The prioritization of shopping media for CPG brands.

- A case study of brands on Target.com on how this retailer (and others) have introduced a new channel for brand marketers to engage consumers where they are making the majority of purchase decisions: online.

- How CPG brands are leveraging real-time data from shopping media to capture consumer insights and market trends.
';

$resultText = Markdown($testText);

var_dump($resultText);

输出看起来与您所期望的相当,

string(649) "<p>Since its launch, major CPG brands, endemic as well as non-endemic, have flocked to retail websites to reach consumers deep in the purchase funnel through shopping media. In this session, you will hear about:</p>

<ul>
<li><p>The prioritization of shopping media for CPG brands.</p></li>
<li><p>A case study of brands on Target.com on how this retailer (and others) have introduced a new channel for brand marketers to engage consumers where they are making the majority of purchase decisions: online.</p></li>
<li><p>How CPG brands are leveraging real-time data from shopping media to capture consumer insights and market trends.</p></li>
</ul>
"

我假设在数据进入降价解析器之前或之后有其他东西篡改了数据。但根据数据,Markdown 解析器不会创建

标签。你必须看看其他地方:(

I could not reproduce what you describe with the version you've been given:

<?php
include(__DIR__.'/php-markdown/markdown.php');


$testText = 'Since its launch, major CPG brands, endemic as well as non-endemic, have flocked to retail websites to reach consumers deep in the purchase funnel through shopping media. In this session, you will hear about:

- The prioritization of shopping media for CPG brands.

- A case study of brands on Target.com on how this retailer (and others) have introduced a new channel for brand marketers to engage consumers where they are making the majority of purchase decisions: online.

- How CPG brands are leveraging real-time data from shopping media to capture consumer insights and market trends.
';

$resultText = Markdown($testText);

var_dump($resultText);

The output looks fairly as you might expect it

string(649) "<p>Since its launch, major CPG brands, endemic as well as non-endemic, have flocked to retail websites to reach consumers deep in the purchase funnel through shopping media. In this session, you will hear about:</p>

<ul>
<li><p>The prioritization of shopping media for CPG brands.</p></li>
<li><p>A case study of brands on Target.com on how this retailer (and others) have introduced a new channel for brand marketers to engage consumers where they are making the majority of purchase decisions: online.</p></li>
<li><p>How CPG brands are leveraging real-time data from shopping media to capture consumer insights and market trends.</p></li>
</ul>
"

I assume something else tampering the data before it get's into the markdown parser or afterwards. But based on the data, the markdown parser does not create the <h3> tags. You must look somewhere else :(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文