lark_docx_md

package module
v0.0.0-...-ce6983c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 12 Imported by: 0

README

lark_docx_md

Parse Lark/Feishu Docx into Markdown

Install

go get github.com/A11Might/lark_docx_md

Usage

package main

import (
	"context"
	"fmt"

	"github.com/A11Might/lark_docx_md"
	lark "github.com/larksuite/oapi-sdk-go/v3"
)

func main() {
	processor := lark_docx_md.NewDocxMarkdownProcessor(
		lark.NewClient("appId", "appSecret"),
		"documentId",
		lark_docx_md.DownloadStatic("static", "static"),
		lark_docx_md.UseGhCalloutStyle(),
	)
	md, err := processor.DocxMarkdown(context.Background())
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(md)
}

Example

Origin lark docx:docx

Parse into Markdown:md

A11Might/lark-docx-readme: Use lark docx update github README.md

Inspired by chyroc/lark_docs_md

Documentation

Index

Constants

View Source
const (
	Page           = 1
	Text           = 2
	Heading1       = 3
	Heading2       = 4
	Heading3       = 5
	Heading4       = 6
	Heading5       = 7
	Heading6       = 8
	Heading7       = 9
	Heading8       = 10
	Heading9       = 11
	Bullet         = 12
	Ordered        = 13
	Code           = 14
	Quote          = 15
	Todo           = 17
	Callout        = 19
	Divider        = 22
	Image          = 27
	Table          = 31
	TableCell      = 32
	QuoteContainer = 34
)
View Source
const (
	PlainText = iota + 1
	ABAP
	Ada
	Apache
	Apex
	AssemblyLanguage
	Bash
	CSharp
	Cpp
	C
	COBOL
	CSS
	CoffeeScript
	D
	Dart
	Delphi
	Django
	Dockerfile
	Erlang
	Fortran
	FoxPro
	Go
	Groovy
	HTML
	HTMLBars
	HTTP
	Haskell
	JSON
	Java
	JavaScript
	Julia
	Kotlin
	LateX
	Lisp
	Lua
	MATLAB
	Makefile
	Markdown
	Nginx
	ObjectiveC
	OpenEdgeABL
	PHP
	Perl
	PostScript
	PowerShell
	Prolog
	ProtoBuf
	Python
	R
	RPG
	Ruby
	Rust
	SAS
	SCSS
	SQL
	Scala
	Scheme
	Scratch
	Shell
	Swift
	Thrift
	TypeScript
	VBScript
	VisualBasic
	XML
	YAML
	CMake
	Diff
	Gherkin
	GraphQL
	OpenGLShadingLanguage
	Properties
	Solidity
	TOML
)
View Source
const (
	LightRed = iota + 1
	LightOrange
	LightYellow
	LightGreen
	LightBlue
	LightPurple
	LightGray
	Red
	Orange
	Yellow
	Green
	Blue
	Purple
	Gray
	SilverGray
)
View Source
const (
	AlignLeft = iota + 1
	AlignMid
	AlignRight
)

Variables

This section is empty.

Functions

func UnescapeUrl

func UnescapeUrl(link string) string

Types

type Config

type Config struct {
	StaticDir    string // 如果需要下载静态文件,那么需要指定静态文件的目录
	FilePrefix   string // 针对静态文件,需要指定文件在 Markdown 中的前缀
	StaticAsURL  bool   // 不下载静态文件,直接把静态文件的 URL 插入到 Markdown 中
	UseGhCallout bool   // 高亮块使用 github 样式
}

type DocxMarkdownProcessor

type DocxMarkdownProcessor struct {
	*Config
	LarkClient *lark.Client // lark 客户端
	DocumentId string       // docx 文档 token
}

func NewDocxMarkdownProcessor

func NewDocxMarkdownProcessor(client *lark.Client, documentId string, opts ...Option) *DocxMarkdownProcessor

func (*DocxMarkdownProcessor) BlockBulletMarkdown

func (p *DocxMarkdownProcessor) BlockBulletMarkdown(ctx context.Context, block *larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockCalloutMarkdown

func (p *DocxMarkdownProcessor) BlockCalloutMarkdown(ctx context.Context, blocks []*larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockCodeMarkdown

func (p *DocxMarkdownProcessor) BlockCodeMarkdown(ctx context.Context, block *larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockDividerMarkdown

func (p *DocxMarkdownProcessor) BlockDividerMarkdown(ctx context.Context) string

func (*DocxMarkdownProcessor) BlockHeadingMarkdown

func (p *DocxMarkdownProcessor) BlockHeadingMarkdown(ctx context.Context, block *larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockImageMarkdown

func (p *DocxMarkdownProcessor) BlockImageMarkdown(ctx context.Context, block *larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockOrderedMarkdown

func (p *DocxMarkdownProcessor) BlockOrderedMarkdown(ctx context.Context, block *larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockPageMarkdown

func (p *DocxMarkdownProcessor) BlockPageMarkdown(ctx context.Context, block *larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockQuoteContainerMarkdown

func (p *DocxMarkdownProcessor) BlockQuoteContainerMarkdown(ctx context.Context, blocks []*larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockQuoteMarkdown

func (p *DocxMarkdownProcessor) BlockQuoteMarkdown(ctx context.Context, block *larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockTableMarkdown

func (p *DocxMarkdownProcessor) BlockTableMarkdown(ctx context.Context, table [][]*larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockTextMarkdown

func (p *DocxMarkdownProcessor) BlockTextMarkdown(ctx context.Context, block *larkdocx.Block) string

func (*DocxMarkdownProcessor) BlockTodoMarkdown

func (p *DocxMarkdownProcessor) BlockTodoMarkdown(ctx context.Context, block *larkdocx.Block) string

func (*DocxMarkdownProcessor) DocxBlockMarkdown

func (p *DocxMarkdownProcessor) DocxBlockMarkdown(ctx context.Context, item *ProcessItem) (md string)

func (*DocxMarkdownProcessor) DocxMarkdown

func (p *DocxMarkdownProcessor) DocxMarkdown(ctx context.Context) (string, error)

func (*DocxMarkdownProcessor) TextMarkdown

func (p *DocxMarkdownProcessor) TextMarkdown(ctx context.Context, text *larkdocx.Text) string

type Option

type Option func(*DocxMarkdownProcessor)

func DownloadStatic

func DownloadStatic(staticDir, filePrefix string) Option

DownloadStatic 下载图片等静态文件

func UseGhCalloutStyle

func UseGhCalloutStyle() Option

UseGhCalloutStyle 使用 github 高亮块样式

type ProcessItem

type ProcessItem struct {
	BlockType      *int                // block 类型
	Normal         *larkdocx.Block     // 普通块
	Callout        []*larkdocx.Block   // 高亮块
	Table          [][]*larkdocx.Block // 表格
	QuoteContainer []*larkdocx.Block   // 引用容器
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL