[英]knitr, pandoc: embeding SVG directly to HTML document
我正在使用knitr自動生成報告到mediawiki頁面。 報告輸出通過pandoc以HTML格式顯示 。 但我在將數據上傳到維基站點時遇到問題。 所以我想我會使用SVG設備並將代碼包含在最終文檔中,而不是依賴於外部文檔。 但是我無法使用knitr或pandoc來做這件事。 有沒有人知道創建嵌入式SVG而不是鏈接到圖像的pandoc或knitr選項? 甚至一個小的外殼腳本,取代<img src="myFigure.svg">
用的內容myFigure.svg
。
我最終使用一個簡單的python腳本來完成這項工作
from sys import argv
import re
import os
def svgreplace(match):
"replace match with the content of a filename match"
filename = match.group(1)
with open(filename) as f:
return f.read()
def svgfy(string):
img = re.compile(r'<img src="([^"]*\.svg)"[^>]*>')
return img.sub(svgreplace, string)
if __name__ == "__main__":
fname = argv[1]
with open(fname) as f:
html = f.read()
out_fname = fname + ".tmp"
out = open(out_fname, 'w')
out.write(svgfy(html))
out.close()
os.rename(out_fname, fname)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.