Java markdown转doc,Remark-java: Remark-java 是一个 java 库,实现将 HTML 内容转成 Markdown 格式...

OverZealous Creations Remark

Remark is a library for taking (X)HTML input and outputting clean Markdown, Markdown Extra, or MultiMarkdown compatible text. The purpose of this conversion is mainly to allow for the use of client-side HTML GUI editors while retaining safe, mobile-device editable markdown text behind the scenes. It is recommended that the markdown text is stored, to reduce XSS attacks by code injection.

About this fork

This fork was created in order to convert Maven build system to Gradle and deploy library to Maven Central Repository.

implementation "com.kotcrab.remark:remark:1.2.0"

Example Usage Scenario

The user logs in from their desktop.

Adding some text, the user inputs into a full-featured GUI, such as Dojo's rich text editor, or any of these editors.

The webserver takes the generated HTML, which may contain a lot of bad HTML, depending on the browser, and passes it to Remark.

Remark passes the HTML to jsoup, to clean up the input text, which strips unsupported HTML tags (the text will remain).

Remark walks the generated DOM tree, and outputs clean, structured markdown text.

The markdown text is returned.

The webserver stores this markdown text for future display.

The user chooses to re-edit the HTML text from their desktop.

The webserver converts the Markdown back to HTML, and sends it to the client.

Repeat the steps above to save it.

The user later logs in from their mobile device.

Mobile devices often not support rich text editing through the web browser.

So, instead, render a plain text field with the raw markdown text.

Because markdown is relatively easy to read and edit, the user can make simple changes without struggling with hundreds of messy HTML tags.

Advanced Features

Remark can be configured to output extra functionality beyond straight markdown.

Markdown Extra tables or Multimarkdown tables (which add column spanning support), including a best-guess attempt at alignment (based on style or align attributes)

Reversal of various smart HTML entities or unicode characters:

“ (“) and ” (”) become "

‘ (‘), ’ (’), and ' become '

« («) becomes <<

» (») becomes >>

… (…) becomes ...

&endash; (–) becomes --

&emdash; (—) becomes ---

Simplified hardwraps — A
is converted to just a single linebreak, instead of (space)(space)(newline), common in most third-party markdown renderers

Autolinks — a link that has the same content as it's label (and starts with http or https) is simply rendered as is, like http://www.overzealous.com

Fenced code blocks, using either Markdown Extra's format using ~~~, or Github's format using ```

Customization of allowed HTML tags - not really recommended.

The basic theory is that you match the extensions to your Markdown conversion library.

Dependencies

Remark depends on jsoup and Apache Commons Lang 3. If you want to use it from the command line, it also depends on Apache Commons CLI. Alternatively, you can download the standalone version of the Jar, which contains all the dependencies.

jsoup uses the MIT License, which is roughly comparable to the Apache 2.0 License used by Remark and the Apache dependencies.

During testing, Remark also depends on some additional libraries, which are automatically downloaded by the gradle build script.

License

Remark is released under the Apache 2.0 license.

Copyright 2011 OverZealous Creations, LLC

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要更改 `markdown-navbar` 组件中生成的导航链接的 `data-id` 属性,你可以使用 `remark` 和 `remark-slug` 插件来为 markdown 中的标题添加自定义的 `slug`,然后在 `markdown-navbar` 中使用 `slug` 来覆盖默认的 `id` 和 `data-id` 属性。 以下是一个示例代码: ```jsx import React from 'react'; import ReactMarkdown from 'react-markdown'; import Navbar from 'markdown-navbar'; import 'markdown-navbar/dist/navbar.css'; import remarkSlug from 'remark-slug'; import unified from 'unified'; const MyMarkdown = ({ source }) => { const processor = unified().use(remarkSlug); const markdownAST = processor.parse(source); const headings = []; processor.runSync(markdownAST).children.forEach((node) => { if (node.type === 'heading') { // 获取自定义的 slug const slug = node.data?.hProperties?.slug; // 将 slug 覆盖默认的 id 和 data-id 属性 node.data = { hProperties: { id: slug, 'data-id': slug, }, }; headings.push({ level: node.depth, title: node.children[0].value, slug, }); } }); return ( <> <Navbar headings={headings} /> <ReactMarkdown astPlugins={[remarkSlug]}>{source}</ReactMarkdown> </> ); }; export default MyMarkdown; ``` 在这个示例中,我们使用 `unified` 和 `remark-slug` 插件为 markdown 中的标题添加了自定义的 `slug`,然后在 `MyMarkdown` 组件中将 `slug` 赋值给了标题节点的 `id` 和 `data-id` 属性。最后,我们将生成的导航栏和 markdown 内容渲染了出来。 需要注意的是,`data-id` 属性并非标准的 HTML 属性,如果你需要使用这个属性来进行一些操作,可能需要自己编写相应的 JavaScript 代码来实现
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值