GVKun编程网logo

如何在角度数据中显示或任何原始html?

21

在本文中,我们将详细介绍如何在角度数据中显示或任何原始html?的各个方面,同时,我们也将为您带来关于android–如何在TextView中显示HTML?、asp.net-mvc-3–是否可能显示从

在本文中,我们将详细介绍如何在角度数据中显示或任何原始html?的各个方面,同时,我们也将为您带来关于android – 如何在TextView中显示HTML?、asp.net-mvc-3 – 是否可能显示从ASP.NET MVC 3中的数据库的原始Html?、Clojure,使用Enlive从选择器中提取原始HTML?、Django输出word文件(.doc),仅在内容中显示原始html的有用知识。

本文目录一览:

如何在角度数据中显示或任何原始html?

如何在角度数据中显示或任何原始html?

如何显示 为空格而不显示为字符串。有raw像树枝一样的过滤器吗?

<div>{{item}}</div>$scope.item = ''&nbsp;'';

但是结果逃不过了&amp;nbsp;。我需要这个,因为'' ''高度为0。

答案1

小编典典

使用 ngBindHtml
可以轻松完成

对于1.2.x以上版本的Angular:

ng-bind-html

工作演示

html

<div ng-app=''myApp'' ng-controller="Controller">   <div ng-bind-html="item"></div></div>

脚本

var app = angular.module(''myApp'', [''ngSanitize'']);app.controller(''Controller'', function ($scope, $sce) {   $scope.item = ''What&nbsp;Is&nbsp;Your&nbsp;Name?'';});

对于Angular 1.0.x版本:

工作演示

ng-bind-html-unsafe

html

<div ng-app=''myApp'' ng-controller="Controller">   <div ng-bind-html-unsafe="item"></div></div>

脚本

var app = angular.module(''myApp'', []);app.controller(''Controller'', function ($scope) {   $scope.item = ''What&nbsp;Is&nbsp;Your&nbsp;Name?'';});

android – 如何在TextView中显示HTML?

android – 如何在TextView中显示HTML?

我有简单的HTML:

<h2>Title</h2><br>
<p>description here</p>

我想在TextView中显示HTML样式的文本.这该怎么做?

解决方法:

您需要使用Html.fromHtml()在XML字符串中使用HTML.简单地在布局XML中引用带有HTML的String将不起作用.

这是你应该做的:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    textView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>", Html.FROM_HTML_MODE_COMPACT));
} else { 
    textView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
}

asp.net-mvc-3 – 是否可能显示从ASP.NET MVC 3中的数据库的原始Html?

asp.net-mvc-3 – 是否可能显示从ASP.NET MVC 3中的数据库的原始Html?

我在我的数据库中有一个表,其中的一个属性是一个Html页面(没有html,head和body标签),我打算把它放在我的一个视图的中间 – 我称之为cotroller方法接受一个参数,并返回一个传递此html大字符串作为模型的视图。我搜索它(不是很多,我承认),并找到以下方法:
<%= System.Web.HttpUtility.HtmlDecode(yourEncodedHtmlFromYouDatabase) %>

那被发现here in stackoverflow.当我尝试一个类似的剃刀aproach,我结束了这:

@System.Web.HttpUtility.HtmlDecode("<h1>Test</h1>")

这是想法,但它没有像我计划的工作。

解决方法

你所需要的是:@ Html.Raw(yourEncodedHtmlFromYouDatabase)

我假设数据库中的html已经被正确地清理(或至少从可靠的源),因为如果没有,你可能开始自己跨站点脚本攻击。

你的方法不工作的原因是Razor HTML编码输出默认情况下(每次你使用@显示的东西)。 Html.Raw告诉Razor你信任的HTML,你想显示它,而不进行编码它(因为它已经是原始的HTML)。

Clojure,使用Enlive从选择器中提取原始HTML?

Clojure,使用Enlive从选择器中提取原始HTML?

我需要从 HTML页面的某个部分检索一些原始HTML.

我编写了刮刀并抓取了相应的div,但它返回了一个标签贴图.

(:use [net.cgrand.enlive-html :as html])

(defn fetch-url [url]
 (html/html-resource (java.net.URL. url)))

(defn parse-test []
  (let [url "http://www.ncbi.nlm.nih.gov/pubmedhealth/PMH0000928/"
        url-data (fetch-url url)
        id "a693025"]
    (first (html/select url-data [(keyword (str "#" id "-why"))]))))

这输出:

{:tag :div,:attrs {:class "section",:id "a693025-why"},:content ({:tag :h2,:attrs nil,:content ({:tag :span,:attrs {:class "title"},:content ("Why is this medication prescribed?")})} {:tag :p,:content ("Zolpidem is used to treat insomnia (difficulty falling asleep or staying asleep). Zolpidem belongs to a class of medications called sedative-hypnotics. It works by slowing activity in the brain to allow sleep.")})}

如何将其转换为原始html?我找不到任何活跃的功能来做到这一点.

解决方法

(apply str (html/emit* [(parse-test)]))
; => "<div class=\"section\" id=\"a693025-why\"><h2><span class=\"title\">Why is this medication prescribed?</span></h2><p>Zolpidem is used to treat insomnia (difficulty falling asleep or staying asleep). Zolpidem belongs to a class of medications called sedative-hypnotics. It works by slowing activity in the brain to allow sleep.</p></div>"

Django输出word文件(.doc),仅在内容中显示原始html

Django输出word文件(.doc),仅在内容中显示原始html

我正在使用Django 1.4编写一个Web应用程序,我希望其中一个视图使用以下代码输出mirosoft word文档:

response = HttpResponse(view_data,content_type='application/vnd.ms-word')
response['Content-Disposition'] = 'attachment; filename=file.doc'
return response

然后,我可以成功下载file.doc文件,但是当我打开.doc文件时,只能找到这样的原始html文件。

<h1>some contents</h1>

不是heading1标题。

我是python和Django的新手,我知道这可能是html转义的问题,有人可以帮助我吗?谢谢 !:)

今天的关于如何在角度数据中显示或任何原始html?的分享已经结束,谢谢您的关注,如果想了解更多关于android – 如何在TextView中显示HTML?、asp.net-mvc-3 – 是否可能显示从ASP.NET MVC 3中的数据库的原始Html?、Clojure,使用Enlive从选择器中提取原始HTML?、Django输出word文件(.doc),仅在内容中显示原始html的相关知识,请在本站进行查询。

本文标签: