cebe/markdown-latex

一个超级快速、高度可扩展的PHP markdown解析器,将markdown文件转换为latex

1.1.5 2019-05-21 13:27 UTC

This package is auto-updated.

Last update: 2024-09-22 03:52:04 UTC


README

Latest Stable Version Total Downloads Build Status Code Coverage Scrutinizer Quality Score

这是一个用PHP编写的markdown解析器,可以将markdown转换为LaTeX。

实现基于 cebe/markdown

安装

需要PHP 5.4或更高版本才能使用。

建议通过 composer 安装,在您的 composer.json 文件的 require 部分添加以下内容

"cebe/markdown-latex": "*"

然后运行 composer update

使用方法

在您的PHP项目中

要直接使用解析器,只需创建一个提供的flavor类的实例,并调用parse()parseParagraph()方法

// default markdown and parse full text
$parser = new \cebe\markdown\latex\Markdown();
$parser->parse($markdown);

// use github
$parser = new \cebe\markdown\latex\GithubMarkdown();
$parser->parse($markdown);

// parse only inline elements (useful for one-line descriptions)
$parser = new \cebe\markdown\latex\GithubMarkdown();
$parser->parseParagraph($markdown);

命令行脚本

您可以使用它来渲染此README

bin/markdown-latex README.md > output.tex

使用GitHub风格的markdown

bin/markdown-latex --flavor=gfm README.md > output.tex

或将原始markdown描述转换为html,使用Unix管道

curl http://daringfireball.net/projects/markdown/syntax.text | bin/markdown-latex > output.tex

要创建LaTeX文档,您必须将生成的LaTeX源代码包含在LaTeX文档 main.tex

\documentclass[a4paper, 12pt]{article}

% english and utf8
\usepackage[british]{babel}
\usepackage[utf8]{inputenc}

% url support
\usepackage{url}

% make links clickable
\usepackage{hyperref}

% code listings
\usepackage{listings}

% include images
\usepackage{graphicx}

% better tables using tabularx
\usepackage{tabularx}

% support github markdown strikethrough
% http://tex.stackexchange.com/questions/23711/strikethrough-text
\usepackage{ulem}

\begin{document}

	\include{output.tex}

\end{document}

使用 pdflatex main.tex 生成PDF。