English 中文(简体)
如何在拉拉维尔用超文本密码信标显示博客员额
原标题:How to display blog post with HTML code snippets in Laravel
  • 时间:2021-08-19 13:54:06
  •  标签:
  • laravel

我的博客职位在<代码>text格式的行文中节省下来,我可以找到在段落之间显示超文本的方法,正如你在下文中看到的那样。

I m using >Prismjs<pre><code></code></pre> tags。

“entergraph

在代码栏中,应有两个<代码><div>标记,不展示。

Looks like this in the database table

Laravel is a web application framework with expressive, elegant syntax. A web framework provides a structure and starting point for creating your application, allowing you to focus on creating something amazing while we sweat the details.

Laravel strives to provide an amazing developer experience while providing powerful features such as thorough dependency injection, an expressive database abstraction layer, queues and scheduled jobs, unit and integration testing, and more.

Whether you are new to PHP or web frameworks or have years of experience, Laravel is a framework that can grow with you. We ll help you take your first steps as a web developer or give you a boost as you take your expertise to the next level. We can t wait to see what you build.

<pre><code class="lang-html">
<div>test</div>
</code></pre>

在我的<条码>中,请人发言。 用<代码>{!

如果我使用<代码><pre<<code category=“lang-html”>{-post->-code>/code>/</pre> on the blade view the Code isprofile but I have no way to including the text of the post. 只努力显示守则。

面对无法做两件事的问题,我是一件事。

最佳回答

There is no straightforward way of doing this by using standard Laravel/Blade output options. However it s possible to accomplish it with a little bit of extra code.

页: 1 为什么发生这种情况?

<代码><pre>或<code> 均在阻止浏览器将案文解释为html代码。 它们的目的不同:一是告诉浏览器白天空间是重要的,二是说内容是某些计算机代码,需要用不同的打字显示。 在这两种情况下,如果有效超文本在标签内,则将视作超文本处理。

https://prismjs.com/#examples”rel=“nofollow noreferer” 您需要从中删除的内容:

Note: You have to escape all < and & characters inside < code > elements (code blocks and inline snippets) with < and & respectively, or else the browser might interpret them as an HTML tag or entity. If you have large portions of HTML code, you can use the Unescaped Markup plugin to work around this.

2. Solutions

解决你的问题有不同的方法。 页: 1 在将其保存到数据库之前,仅打印出不可靠的原始内容或,修改产出,并确保你只从<代码><code> tag中途经。

由于我们不了解你使用的投入方法,因此,请把重点放在第二项选择上,以修改产出。

A. PrismJS

它们 你们可以使用Une diedmarkup<>plugin解决你的问题。 我没有这方面的任何经验,但口号是,无须逃避任何......>。

您只需要列入这一缩略语,然后,您有两种选择:互换(<pre><code> for <script>,或者使用超文本-comment总结你的代码(如果你在代码上没有其他评论的话)。

仅看它们的详细资料实例

<>PHP

你们可以使用购买力平价将案文从数据库中删除,并逃避所需内容的内容。 在你的情况下,这是<编码>编码>。 你需要写一下自己的执行情况,或使用我为你的案件写的文字。

然后,你可以做:

{!! Houdini::escape($content) !!}

包括或自动载荷以下类别:

class Houdini
{
    /**
     * Escape the html characters inside a given HTML element
     *
     * @param string $text The text we are trying to clean
     * @param string $element The name of the elements to be escaped
     * @param bool $fix Should we try to make the text a valid HTML by wrapping it with divs
     *
     * @return string
     */
    public static function escape($text, $element =  code , $fix = true) {
        $dom = new DOMDocument;
        $dom->loadXML($fix ?  <div>  . $text .  </div>  : $text);

        $nodes = $dom->getElementsByTagName($element);
        foreach ($nodes as $node) {
            $content =   ;
            foreach ($node->childNodes as $child) {
                $content .= self::escapeRecursively($child);
            }
            $node->nodeValue = htmlspecialchars($content);
        }
        return $dom->saveHTML();
    }

    /**
     * Escape node and note contents
     *
     * @param $node
     * @return string
     */
    protected static function escapeRecursively($node) {
        if ($node instanceof DOMText)
            return $node->textContent;

        $content = "<$node->nodeName>";
        foreach ($node->childNodes as $child) {
            $content .= self::escapeRecursively($child);
        }

        return "$content</$node->nodeName>";
    }
}

C. Java

您可以包括以下javascript代码,该编码将涵盖所有<代码><代码>要素,并确定内身。 Html as the innerText.

    document.querySelectorAll("code").forEach(el => el.innerText = el.innerHTML);

<>说明: 如果在数据库中保留这些段落,仅与新线分开,未在<代码><p>上填满。 您将使用这一解决办法和<代码>nl2br()一并处理。

D. Deprecated <xmp>

<pre><code class="lang-html">
<xmp><div>test</div></xmp>
</code></pre>

There WAS after all an HTML tag specifically to show example HTML code as it is, but it was deprecated in HTML 3.2, BUT it seems the tag is widely supported and wrapping the code contents can be a quick and dirty solution for your case. You can see the support tables here: https://caniuse.com/?search=xmp

详见:

可以通过在保存数据库之前添加标签,或者在客户一方印刷 Java本的产出时,或者在将产出转至lade版模板之前,加上PHP来做到这一点。

3. 其他帮助我回答问题的StackOverflow员额

问题回答

You may find the @verbatim directive useful - https://laravel.com/docs/10.x/blade#the-at-verbatim-directive

This will allow you to display components inside of the <code> tag without Blade attempting to render your component.

具体例子如下:

<pre>
    <code class="lang-html">
        @verbatim <div>test</div> @endverbatim
    </code>
</pre>




相关问题
Table of calificacions in php and laravel

I created a table in order to show the name of the students, name of the subjects and the grade of the subject of the student I have the next code: this is the index part <form action="{{ ...

How to fix CORS for Capacitor/Quasar App in a Laravel API

I have an App built on top of Quasar and Capacitor, with an API built on top of Laravel. Everything works well on the dev environment until I build and install the app on my phone, then I keep getting ...

Laravel +Vuejs CORS issue

I am facing a dilemma wit the CORS issue. I have application that is configured as follow: API: https://abc.mydomain.com (laravel) front end: https://subdomain.mydomain.com(VueJS) Both applications ...

Laravel wrong redirecting to login page after login

In a multi tenancy with subdomain enviroment (http://zapburger.dex.local) when user fills login form with valid data and make login, laravel redirect to dashboard route (as expected) and then redirect ...