![](/img/trans.png)
[英]Why is italic text not displayed in html files generated from Docbook/Oxygen
[英]using font awesome in Docbook generated HTML
在docbook xml文件中創建占位符時應采取哪些步驟,該占位符將在生成的HTML輸出中使用超棒的字體。 在DocBook生成的HTML輸出中查找使用字體真棒字體的xslt示例。
希望這個答案不是tl; dr。 如果您希望我將其分為3個單獨的答案,請告訴我。
第一種選擇是在實體聲明中使用HTML標記,就像我在注釋中首先提到的那樣。
優點
缺點
i
html元素無效,因此您的文檔中將出現驗證錯誤 您需要做的是:
更改您的實體聲明,如下所示:
<!ENTITY fa-birthday-cake "<i class='fa fa-birthday-cake' xmlns=''></i>">
這與我的第一句話有些不同。 我添加了一個空的名稱空間,以使i
元素不會自動出現在默認名稱空間中。
將鏈接添加到head
的字體真棒CSS中。 (我讓它指向本地的超棒字體。)
<link rel="stylesheet" href="font-awesome-4.3.0/css/font-awesome.min.css"/>
為了進行測試,我修改了frameworks/docbook/xsl/html/profile-docbook.xsl
。 我在match="*" mode="process.root"
模板中的第460行附近添加了link
。
添加模板以匹配i
元素,以免被替換。
<xsl:template match="i"> <xsl:copy-of select="."/> </xsl:template>
例...
Docbook輸入
<!DOCTYPE section [
<!ENTITY fa-birthday-cake "<i class='fa fa-birthday-cake' xmlns=''></i>">
]>
<section xmlns="http://docbook.org/ns/docbook" version="5.0">
<title>Section Template Title</title>
<para>birthday cake: &fa-birthday-cake;</para>
</section>
HTML輸出 (使用DocBook HTML轉換方案)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="font-awesome-4.3.0/css/font-awesome.min.css">
<title>Section Template Title</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="d56e3"></a>Section Template Title</h2>
</div>
</div>
<div></div>
<hr>
</div>
<p>birthday cake: <i class='fa fa-birthday-cake'></i></p>
</div>
</body>
</html>
渲染HTML
第二種選擇是在實體聲明中使用字體真棒類,並使用具有特殊role
屬性的symbol
元素保存引用。
優點
symbol
是DocBook元素,因此您不應該存在驗證問題 缺點
symbol
可能無法在使用超棒字體圖標的所有位置中都可用 symbol
的技巧(雖然可能不如第一種選擇那樣技巧) 您需要做的是:
更改您的實體聲明,如下所示:
<!ENTITY fa-birthday-cake "fa-birthday-cake">
將鏈接添加到head
的字體真棒CSS中。 (我讓它指向本地的超棒字體。)
<link rel="stylesheet" href="font-awesome-4.3.0/css/font-awesome.min.css"/>
為了進行測試,我修改了frameworks/docbook/xsl/html/profile-docbook.xsl
。 我在match="*" mode="process.root"
模板中的第460行附近添加了link
。
添加模板以使symbol
元素與“ fa” role
匹配,然后輸出i
。 ( d
綁定到profile-docbook.xsl中的http://docbook.org/ns/docbook
命名空間)
<xsl:template match="d:symbol[@role='fa']"> <i class="fa {.}"></i> </xsl:template>
例...
Docbook輸入
<!DOCTYPE section [
<!ENTITY fa-birthday-cake "fa-birthday-cake">
]>
<section xmlns="http://docbook.org/ns/docbook" version="5.0">
<title>Section Template Title</title>
<para>birthday cake: <symbol role="fa">&fa-birthday-cake;</symbol></para>
</section>
HTML輸出 (使用DocBook HTML轉換方案)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="font-awesome-4.3.0/css/font-awesome.min.css">
<title>Section Template Title</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="d56e3"></a>Section Template Title</h2>
</div>
</div>
<div></div>
<hr>
</div>
<p>birthday cake: <i class='fa fa-birthday-cake'></i></p>
</div>
</body>
</html>
渲染HTML
第三個選項是切換到XSLT 2.0並使用xsl:character-map
。
優點
缺點
exslt:node-set()
使用。) 您需要做的是:
使您的實體聲明看起來像這樣(基於您的其他問題https://stackoverflow.com/questions/30055181/how-do-i-insert-fonts-as-an-entity-in-docbook ):
<!ENTITY fa-birthday-cake "">
將鏈接添加到head
的字體真棒CSS中。 (我讓它指向本地的超棒字體。)
<link rel="stylesheet" href="font-awesome-4.3.0/css/font-awesome.min.css"/>
為了進行測試,我修改了frameworks/docbook/xsl/html/profile-docbook.xsl
。 我在match="*" mode="process.root"
模板中的第460行附近添加了link
。
將xsl:stylesheet
版本更改為2.0。
導入xsl:character-map
。
<xsl:include href="font-awesome.xsl"/>
我提供了一個示例“ font-awesome.xsl”。 我今天有完整的版本,基於字體真棒的速查表(2015-05-06)。 添加全部內容會使我的答案超出字符數限制; 讓我知道你是否需要它。
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:character-map name="fa"> <xsl:output-character string="<i class='fa fa-birthday-cake'></i>" character=""/> </xsl:character-map> </xsl:stylesheet>
在xsl:output
引用字符映射(帶有use-character-maps
)。
<xsl:output method="html" encoding="ISO-8859-1" indent="no" use-character-maps="fa"/>
可能的其他更改。
就像“缺點”部分中提到的那樣,您可能需要根據所使用的處理器對docbook樣式表進行一些更改。 我使用了Saxon-HE 9.5.1.3。 我通過復制DocBook HTML轉換方案並更改處理器來做到這一點。
例...
Docbook輸入
<!DOCTYPE section [
<!ENTITY fa-birthday-cake "">
]>
<section xmlns="http://docbook.org/ns/docbook" version="5.0">
<title>Section Template Title</title>
<para>birthday cake: &fa-birthday-cake;</para>
</section>
HTML輸出 (使用修改后的DocBook HTML轉換方案)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="font-awesome-4.3.0/css/font-awesome.min.css">
<title>Section Template Title</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="d56e3"></a>Section Template Title</h2>
</div>
</div>
<div></div>
<hr>
</div>
<p>birthday cake: <i class='fa fa-birthday-cake'></i></p>
</div>
</body>
</html>
渲染HTML
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.