Skip to content

Commit

Permalink
Use HTML tag for text mark style. Fix #10
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Jun 4, 2024
1 parent 51f57e1 commit 52d21df
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 37 deletions.
12 changes: 6 additions & 6 deletions feishu-docx/src/markdown_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,14 @@ export class MarkdownRenderer extends Renderer {
let escape = true;
if (style) {
if (style.bold) {
preWrite = '**';
postWrite = '**';
preWrite = '<b>';
postWrite = '</b>';
} else if (style.italic) {
preWrite = '_';
postWrite = '_';
preWrite = '<em>';
postWrite = '</em>';
} else if (style.strikethrough) {
preWrite = '~~';
postWrite = '~~';
preWrite = '<del>';
postWrite = '</del>';
} else if (style.underline) {
preWrite = '<u>';
postWrite = '</u>';
Expand Down
9 changes: 4 additions & 5 deletions feishu-docx/tests/fixtures/case0.expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

Feishu2Md 已开源并发布在 Github 中:https://github.com/Wsine/feishu2md

**下载 feishu2md **-** **得益于 golang 本身的多平台编译特性,我已经为 Windows/Linux/Mac 都预编译了该工具的可执行文件,可以直接从 [Github Release](https://github.com/Wsine/feishu2md/releases) 中下载,从压缩包中提取自己平台的 feishu2md 二进制可执行文件即可,建议放置在 PATH 路径中。
<b>下载 feishu2md </b>-<b> </b>得益于 golang 本身的多平台编译特性,我已经为 Windows/Linux/Mac 都预编译了该工具的可执行文件,可以直接从 [Github Release](https://github.com/Wsine/feishu2md/releases) 中下载,从压缩包中提取自己平台的 feishu2md 二进制可执行文件即可,建议放置在 PATH 路径中。

**生成配置文件** - feishu2md 需要使用飞书的 Open API 提取飞书文档,因此需要配置相应的 App ID 和 App Secret 进行 API 的调用。首先,进入飞书的 [开发者后台](https://open.feishu.cn/app) 然后创建一个企业自建应用,信息可以任意填,发布但不必等待审核通过。然后在创建的应用页面中,找到「凭证与基础信息」,即可找到 App ID 和 App Secret 信息。
<b>生成配置文件</b> - feishu2md 需要使用飞书的 Open API 提取飞书文档,因此需要配置相应的 App ID 和 App Secret 进行 API 的调用。首先,进入飞书的 [开发者后台](https://open.feishu.cn/app) 然后创建一个企业自建应用,信息可以任意填,发布但不必等待审核通过。然后在创建的应用页面中,找到「凭证与基础信息」,即可找到 App ID 和 App Secret 信息。

<img src="boxcnh7JKLbFaWhHKHveYzGMNZg" src-width="1168" src-height="555"/>

Expand All @@ -51,7 +51,7 @@ Feishu2Md 已开源并发布在 Github 中:https://github.com/Wsine/feishu2md

将 App ID 和 App Secret 填入配置文件 config.json 中的相应位置。另外,image_dir 配置项为存放文档中图片的文件夹名称。

**下载飞书文档** - 通过 `feishu2md 你的飞书文档链接` 直接下载,文档链接可以通过 分享 &gt; 开启链接分享 &gt; 复制链接 获得。
<b>下载飞书文档</b> - 通过 `feishu2md 你的飞书文档链接` 直接下载,文档链接可以通过 分享 &gt; 开启链接分享 &gt; 复制链接 获得。

<img src="boxcnqt9YDTirkKlTATlQI025Ig" src-width="1538" src-height="488"/>

Expand All @@ -69,5 +69,4 @@ feishu2md [一日一技:飞书文档转换为 Markdown](doccnrOvzeQ8BSnfsXj8jw

由于 lark_docs_md 是使用 golang 实现的,因此这也是我首次使用 golang 进行开发。对于开发小工具,整体的开发体验非常良好,而且还能编译得到二进制以及享受多平台编译的好处。工具可能还有一些不是很完善的地方,如有问题可以提 issue,我有时间会进行修复的。

最后,欢迎试用,欢迎 PR ~

最后,欢迎试用,欢迎 PR ~
20 changes: 10 additions & 10 deletions feishu-docx/tests/fixtures/case1.expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Overview

**Markdown** is created by [Daring Fireball](http://daringfireball.net/); the original guideline is [here](http://daringfireball.net/projects/markdown/syntax). Its syntax, however, varies between different parsers or editors. **Typora** is using [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/).
<b>Markdown</b> is created by [Daring Fireball](http://daringfireball.net/); the original guideline is [here](http://daringfireball.net/projects/markdown/syntax). Its syntax, however, varies between different parsers or editors. <b>Typora</b> is using [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/).

[toc]

Expand Down Expand Up @@ -103,13 +103,13 @@ puts markdown.to_html
### Math Blocks
You can render _LaTeX_ mathematical expressions using **MathJax**.
You can render <em>LaTeX</em> mathematical expressions using <b>MathJax</b>.
To add a mathematical expression, input `$$` and press the 'Return' key. This will trigger an input field which accepts _Tex/LaTex_ source. For example:
To add a mathematical expression, input `$$` and press the 'Return' key. This will trigger an input field which accepts <em>Tex/LaTex</em> source. For example:
$$\mathbf{V}_1 \times \mathbf{V}_2 = \begin{vmatrix}\mathbf{i} & \mathbf{j} & \mathbf{k} \\\frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\\frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 \\\end{vmatrix}$$
In the markdown source file, the math block is a _LaTeX_ expression wrapped by a pair of ‘$$’ marks:
In the markdown source file, the math block is a <em>LaTeX</em> expression wrapped by a pair of ‘$$’ marks:
```md
$$
Expand Down Expand Up @@ -208,7 +208,7 @@ This is [an example](http://example.com/) inline link. (`<p>This is <a href="htt

#### Internal Links

**You can set the href to headers**, which will create a bookmark that allow you to jump to that section after clicking. For example:
<b>You can set the href to headers</b>, which will create a bookmark that allow you to jump to that section after clicking. For example:

Command(on Windows: Ctrl) + Click This link will jump to header `Block Elements`. To see how to write that, please move cursor or click that link with `` key pressed to expand the element into markdown source.

Expand Down Expand Up @@ -275,9 +275,9 @@ _single underscores_

output:

_single asterisks_
<em>single asterisks</em>

_single underscores_
<em>single underscores</em>

GFM will ignore underscores in words, which is commonly used in code and names, like this:

Expand Down Expand Up @@ -305,9 +305,9 @@ __double underscores__

output:

**double asterisks**
<b>double asterisks</b>

**double underscores**
<b>double underscores</b>

Typora recommends using the `**` symbol.

Expand All @@ -327,7 +327,7 @@ Use the `printf()` function.

GFM adds syntax to create strikethrough text, which is missing from standard Markdown.

`~~Mistaken text.~~` becomes ~~Mistaken text.~~
`~~Mistaken text.~~` becomes <del>Mistaken text.</del>

### Underlines

Expand Down
32 changes: 16 additions & 16 deletions feishu-docx/tests/fixtures/case3.expect.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
</div>
</div>

导出**飞书知识库**,并按相同目录结构生成 [Static Page Generator](https://www.google.com/search?q=Static+Page+Generator) 支持 Markdown 文件组织方式,用于发布为静态网站。
导出<b>飞书知识库</b>,并按相同目录结构生成 [Static Page Generator](https://www.google.com/search?q=Static+Page+Generator) 支持 Markdown 文件组织方式,用于发布为静态网站。

内容格式支持:[Content Examples](Ks7jwPEtJiyUXckawcRcJ68jnvg) [直接连接](https://longbridge.feishu.cn/wiki/Ks7jwPEtJiyUXckawcRcJ68jnvg)

## **Features**
## <b>Features</b>

- [feishu-docx](https://github.com/longbridgeapp/feishu-pages/tree/main/feishu-docx) - 支持将飞书新版文档 Docx 转换为 Markdown 或其他格式(_目前只支持 Markdown_
- [feishu-docx](https://github.com/longbridgeapp/feishu-pages/tree/main/feishu-docx) - 支持将飞书新版文档 Docx 转换为 Markdown 或其他格式(<em>目前只支持 Markdown</em>
- 目录结构组织
- 图片下载
- 与 GitHub Actions 结合
- 生成支持 [Docusaurus](https://docusaurus.io/) 支持的 Markdown 格式,以实现目录结构组织(基于 `sidebar_position`

## **Installation**
## <b>Installation</b>

Feishu Pages 可以以 Npm 的方式引入到 Static Page Generator 的项目中。

Expand All @@ -44,13 +44,13 @@ yarn add feishu-pages

[test-file.zip](TVEyb1pmWo8oIwxyL3kcIfrrnGd)

## **Feishu Permissions**
## <b>Feishu Permissions</b>

- `docx:document:readonly`
- `wiki:wiki:readonly`
- `drive:drive:readonly`

## **Configuration**
## <b>Configuration</b>

<table header_column="1" header_row="1">
<colgroup>
Expand All @@ -60,7 +60,7 @@ yarn add feishu-pages
<col width="405"/>
</colgroup>
<thead>
<tr><th><p><strong>名称</strong></p></th><th><p>Description</p></th><th><p>Required</p></th><th><p>Default</p></th></tr>
<tr><th><p><b>名</b><b>称</b></p></th><th><p>Description</p></th><th><p>Required</p></th><th><p>Default</p></th></tr>
</thead>
<tbody>
<tr><td><p>FEISHU_APP_ID</p></td><td><p>飞书应用 ID</p></td><td><p>YES</p></td><td></td></tr>
Expand All @@ -72,9 +72,9 @@ yarn add feishu-pages
</tbody>
</table>

## **Usage**
## <b>Usage</b>

### **创建飞书应用并开通权限**
### <b>创建飞书应用并开通权限</b>

1. 请访问 [https://open.feishu.cn/app](https://open.feishu.cn/app) 创建一个新应用,并获得:
- `App ID`
Expand All @@ -93,21 +93,21 @@ yarn add feishu-pages
5. 在飞书 IM 中创建新群 `Feishu Pages`,将应用添加为该群机器人,知识库管理员在「知识空间设置」-&gt; 「权限设置」-&gt;「添加管理员」中添加,把这个 `Feishu Pages` 群加成 <b>管理员:</b>。
- 否则会遇到 `permission denied: wiki space permission denied` 错误。 [ref](https://open.feishu.cn/document/server-docs/docs/wiki-v2/wiki-qa)

### **获取飞书知识库 space_id**
### <b>获取飞书知识库 </b><b>space_id</b>

我们需要配置 `FEISHU_SPACE_ID` 的环境变量,这个为飞书知识库的 `space_id`,你可以访问知识库设置界面,从 URL 中获取。

例如:`https://your-company.feishu.cn/wiki/settings/6992046856314306562` 这里面 `6992046856314306562``space_id`

### **环境变量配置**
### <b>环境变量配置</b>

Feishu Pages 支持 `.env` 文件,如果执行的根目录有个 `.env` 文件,将会自动读取。

> 请参考 `.env.default` 配置环境变量。
如需在 GitHub Actions 的 CI 流程里面使用,建议添加到 Secrets 中,再通过环境变量的方式获取。

## **从知识库导出 Markdown 文档**
## <b>从知识库导出 Markdown 文档</b>

```bash
cd your-project/
Expand All @@ -116,9 +116,9 @@ yarn feishu-pages

按上面默认的配置,最终会在 `./dist` 目录下生成 Markdown 文件以及导出的图片文件,如果你期望调整目录,可以自己设置 `OUTPUT_DIR` 环境变量。

## **常见问题**
## <b>常见问题</b>

### **Rate Limit 相关错误**
### <b>Rate Limit 相关错误</b>

> Error: request trigger frequency limit
Expand Down Expand Up @@ -167,6 +167,6 @@ yarn feishu-pages
</tbody>
</table>
## **License**
## <b>License</b>
MIT
MIT

0 comments on commit 52d21df

Please sign in to comment.