Typora画图教程

本文主要介绍如何在Typora中画图,翻译自Typora官网中关于画图的文章介绍。

之前已经介绍过如何使用Typora,请参看如下教程入门使用:https://blog.csdn.net/qq_41261251/article/details/102817673

一、概述

Typora supports some Markdown extensions for diagrams, once they are enabled from preference panel.

When exporting as HTML, PDF, epub, docx, those rendered diagrams will also be included, but diagrams features are not supported when exporting markdown into other file formats in current version. Besides, you should also notice that diagrams is not supported by standard Markdown, CommonMark or GFM. Therefore, we still recommend you to insert an image of these diagrams instead of write them in Markdown directly.

译文:

Typora支持一些Markdown图表插件,只需要在偏好设置中开启即可(设置如下)。

在这里插入图片描述

当把导出为HTML、PDF、epub、docx时,被渲染好的图表也会被导出,但是在当前版本(原文发表于2016.8.15,我也不知道那时候是什么版本)中,图表特性在导出文件中不被支持。另外,你应该注意图表在标准Markdown、CommonMark或GFM中不被支持。因此,我们仍然建议你将这些图表作为图像插入到文章中,而不是直接用Markdown绘制。

二、开始画图

2.1 序列图

This feature uses js-sequence, which turns the following code block into a rendered diagram:

这个特性使用了js-sequence,它能将以下代码块转换为渲染好的图表:

​```mermaid
sequenceDiagram
title : 这是标题
Alice->>Bob: Hello Bob, how are you?
Note right of Bob: Bob thinks
Bob-->>Alice: I am good thanks!
Bob ->> Henry: Hello Henry, How are you?
​```
Alice Bob Henry Hello Bob, how are you? Bob thinks I am good thanks! Hello Henry, How are you? Alice Bob Henry 这是标题

相信你能看出一些基本元素的语法,了解更多语法规则,请查看以下链接:

[1]https://bramp.github.io/js-sequence-diagrams/

[2]https://github.com/bramp/js-sequence-diagrams/blob/master/src/grammar.jison

2.2 流程图

This feature uses flowchart.js, which turns the following code block into a rendered diagram:

这个特性使用了flowchart.js,它能将下列代码块转换为图表:

​```mermaid
flowchat
%% 注释
%% 将起始点start命名为st(随便取),然后起始点内容为Start(冒号后的文本)
%% :>超链接地址,当点击该元素时,会跳转到相应网站
st=>start: Start:>http://www.lee-0o0.com
op1=>operation: Your Operation1
op2=>operation: Your Operation2:>http://www.lee-0o0.com
cond=>condition: Yes or No?
io=>inputoutput: catch something...
e=>end

st->op1->op2->io->cond
cond(yes)->e
cond(no)->op1
​```
Created with Raphaël 2.2.0 Start Your Operation1 Your Operation2 catch something... Yes or No? End yes no

关于更多的案例,请查看以下链接:

[1]http://flowchart.js.org/

2.3 Mermaid

Typora also has integration with mermaid, which supports sequence diagrams, flowcharts, Gantt charts, class and state diagrams, and pie charts.

Typora同样支持Mermaid,它将序列图、流程图、甘特图、类图、状态图和饼图整合在一起。

了解更多语法规则,查看以下链接:

[1]https://mermaid-js.github.io/mermaid/#/

2.3.1 序列图
​```mermaid
sequenceDiagram
    Alice->>Bob: Hello Bob, how are you?
    alt is sick
    Bob->>Alice: Not so good :(
    else is well
    Bob->>Alice: Feeling fresh like a daisy
    end
    opt Extra response
    Bob->>Alice: Thanks for asking
    end
​```
Alice Bob Hello Bob, how are you? Not so good :( Feeling fresh like a daisy alt [is sick] [is well] Thanks for asking opt [Extra response] Alice Bob 这是标题
2.3.2 流程图
​```mermaid
graph LR
A[Hard edge] -->B(Round edge)
    B --> C{Decision}
    C -->|One| D[Result one]
    C -->|Two| E[Result two]
​```
One
Two
Hard edge
Round edge
Decision
Result one
Result two
2.3.3 甘特图
​```mermaid
%% Example with selection of syntaxes
        gantt
        dateFormat  YYYY-MM-DD
        title Adding GANTT diagram functionality to mermaid

        section A section
        Completed task            :done,    des1, 2014-01-06,2014-01-08
        Active task               :active,  des2, 2014-01-09, 3d
        Future task               :         des3, after des2, 5d
        Future task2               :         des4, after des3, 5d

        section Critical tasks
        Completed task in the critical line :crit, done, 2014-01-06,24h
        Implement parser and jison          :crit, done, after des1, 2d
        Create tests for parser             :crit, active, 3d
        Future task in critical line        :crit, 5d
        Create tests for renderer           :2d
        Add to mermaid                      :1d

        section Documentation
        Describe gantt syntax               :active, a1, after des1, 3d
        Add gantt diagram to demo page      :after a1  , 20h
        Add another diagram to demo page    :doc1, after a1  , 48h

        section Last section
        Describe gantt syntax               :after doc1, 3d
        Add gantt diagram to demo page      : 20h
        Add another diagram to demo page    : 48h
​```
Mon 06 Mon 13 Mon 20 Completed task Active task Future task Future task2 Completed task in the critical line Implement parser and jison Create tests for parser Future task in critical line Create tests for renderer Add to mermaid Describe gantt syntax Add gantt diagram to demo page Add another diagram to demo page Describe gantt syntax Add gantt diagram to demo page Add another diagram to demo page A section Critical tasks Documentation Last section Adding GANTT diagram functionality to mermaid
2.3.4 类图
​```mermaid
classDiagram
      Animal <|-- Duck
      Animal <|-- Fish
      Animal <|-- Zebra
      Animal : +int age
      Animal : +String gender
      Animal: +isMammal()
      Animal: +mate()
      class Duck{
          +String beakColor
          +swim()
          +quack()
      }
      class Fish{
          -int sizeInFeet
          -canEat()
      }
      class Zebra{
          +bool is_wild
          +run()
      }
​```
Animal +age:int +gender:String +isMamal() +mate() Duck +String beakColor +swim() +quack() Fish -int sizeInFeet -canEat() Zebra +bool is_wild +run()
2.3.5 状态图
​```mermaid
stateDiagram
    [*] --> Still
    Still --> [*]

    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]
​```
Still Moving Crash
2.3.6 饼图
​```mermaid
pie
	title 饼图标题
	"dogs":156
	"cats":100
	"birds":60
​```
49% 32% 19% 饼图标题 dogs cats birds

三、参考资料

[1]http://support.typora.io/Draw-Diagrams-With-Markdown/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值