# Siyuan > --- # What is a Content Block ## Content block definition "Content block" refers to a piece of content, and each piece of such content is identified by a globally unique ID. The ID is automatically generated by the program and has the form: `202008250000-a1b2c3d`, consisting of time and 7 random characters. ## Content block types The most common content block is the familiar paragraph (Paragraph). In traditional Chinese typesetting, paragraphs are usually represented by indentation (two spaces) at the beginning of the paragraph. With the development of the Internet, it has gradually affected the representation of paragraphs. The most commonly used method is to increase the line spacing between paragraphs, or use blank lines to separate paragraphs. In actual use, it is not enough to rely on paragraph typesetting. It is often necessary to use Heading, List, Table, Blockquote, etc. to enrich our typesetting. These typographic styles are not only visually different, but more importantly, they express the semantics of the content to a certain extent. For example, when we see an unordered list, we can know that each list item is in an indiscriminate level relationship, while when we see an ordered list, the opposite is true. Therefore, there are many content blocks types, and different types of content blocks are defined by formatting. Content block/Type ## Combined content blocks A document is a combination of some content blocks, and the content block is the basic unit. This is like Lego bricks, which can be combined using different basic modules. Note: the document itself is also a kind of content block. More precisely, the three content blocks of document block, list block, and block reference block are container blocks, and they can contain any other types of content blocks. Content block/Combine At this point, we have been able to use content blocks to describe all content, so that we can use uniform usage to link content block . Logically, there is no page concept, which reduces unnecessary burdens in use and allows users to focus on the content block. ## Naming and memo We can name each content block, add aliases and memo. Naming and aliases are mainly used for anti-link mention search, and memo are used to record some inconvenient information in the content area. After opening the options for displaying bookmarks, naming, and alias identification in the Settings - Editor, the named content block will be displayed with a frame in the editor. If you name and memo the document block, when the mouse is hovering over the doc tree document, the relevant naming and memo of the document will appear. You can use Embed Content Block to search and summarize the naming and memo, such as listing the content blocks that contain the keyword `short` in the memo: --- # Navigate in the Content Block ## Link There are two types of links in the document content: - Standard URL hyperlinks, opened with a browser, used for Internet resource access - The content block link established by `((id))` is used for two-way linking within SiYuan ## Zoom focus - After selecting focus in the right-click drop-down menu on the block icon, the editor will focus on the content block - Jump in context through the breadcrumb navigation at the top of the editor ## Graph The relationship diagram is divided into document level and global. The relationship diagram of the document is expanded based on the current document block and presents all the content blocks (forward links and reverse links) related to the document; the global relationship diagram is all the block and link relationships in all notebooks. Hold down `Ctrl` and click on the node: jump to the node. ## Backlinks Backlinks are document-level, listing the blocks in the current document where content blocks are quoted and mentioned. ### Links - Hovering the mouse over the reference block icon will pop up a preview floating window - Click the reference block in the backlink list to jump ### Mentions It is mentioned that the name and aliases of the content block in the current document is used as a keyword to search, and the search result is a content block containing these keywords. You can use the link button to convert the mention into a link: the mention will be replaced with `((id "content block name"))`. --- # Content Block Type ## Content Block type cheatsheet Hover the mouse over the content block and the corresponding icon will appear on the left side of the content block. For format usage, please refer to Markdown Complete Demo. | Icon | Type | Meta Type | |---|---|---| | | Paragraph block | Leaf block | | | Heading block | Leaf block | | | Math Formula block | Leaf block | | | Code block | Leaf block | | | Table block | Leaf block | | | HTML block | Leaf block | | | Unordered List block | Container block | | | Ordered List block | Container block | | | Task list block | Container block | | | List Item block | Container block | | | Blockquote block | Container block | | | Super block | Container block | | | Document block | Container block | ## Details of content block types Below we introduce the details of these content block types. Content block/Type ### Paragraph block Here is a sample paragraph. Press Enter directly after a paragraph to form a new paragraph. ### Heading block The above is the heading block, which supports level one to six. ### Mathematical formula block $$ a^2 + b^2 = c^2 $$ ### Code block ```anM= function hello() {} ``` ### Table block | Column 1 | Column 2 | |---|---| | Row One Column One | Row One Column Two | | Row Two Column One | Row Two Column Two | If you need to use `|` in the form, please use `\` to escape, that is, you need to enter `\|`. ### HTML block  好 hǎo  世 shì  界 jiè
Hello World Note: The code in the HTML block will not be safely filtered when using it. Please confirm the code is safe before using it to avoid cross-site scripting (XSS). ### Unordered List Block - List item one - List item two The unordered list block is a type container block. If you need to wrap a line in a list item, use Shift Enter. ### Ordered List Block 1. List item one 2. List item two An ordered list block is a type container block. ### Task list block - To do one - To do two The task list block is a type container block. ### List item block The basic usage of outline notes can be realized through the list item block. The list item block is a type container block. ### Blockquote Block > Note that it is not a content block ref, but a block quote (Blockquote). The block reference block is a type container block. ### Super block The super block is a type container block. It can be used to combine continuous content blocks in a document, and also to support horizontal typesetting. ### Documentation block The entire document is a block, and the document block is a type container block. ## Content Block meta type The content block is logically divided into a leaf block and a container block. The leaf block cannot contain other blocks, and the container block can contain other blocks: - List block: can only contain list item blocks - List item block: can contain any other non-document blocks - Blockquote block: can contain any non-document blocks - Super block: can contain any non-document blocks - Document block: can contain any non-document blocks --- # Ref Content Block ## Overview Entering `((` will trigger the content block quotation search, continue to enter as the search keyword, use the up and down keys to select in the search results and press Enter to complete the content block quotation. The complete syntax of the content block quote is: `((id "text"))`, where the `id` is like: `202008250000-a1b2c3d`, consisting of time and 7 random characters, the content block id is when the content block is created It will be automatically generated; the following `text` is the custom anchor text for the content block in the quote. After the content block quote is established, hover the mouse over the anchor text and a preview floating layer will pop up to show the quoted content block. Content block/Reference ## Direction of the ref link - Forwardlink, that is, which other content blocks are used in the current content block - Backlink, that is, the current content block is used by those other content blocks The forward link is included in the content of the current block, which we can see intuitively. Backlinks need to be searched in other documents to know, and it is precisely this information that is more valuable to us. We can use the following two ways to help us better grasp the knowledge points or diverge ideas: - Graph: browse forward and backward link relationships between content blocks - Backlinks: Display the backlinks of the current content block as a text list --- # Embed Content block ## Overview The embed content block is mainly used to summarize the required content blocks, use `{{` and `}}` to wrap SQL scripts on a single line: `{{ SELECT * FROM blocks WHERE content LIKE'%Keyword%' }}`, database table please refer to here. Content block/Embed ## Example - Query list items that contain `content block`: ```c3Fs {{ SELECT * FROM blocks WHERE content LIKE '%content block%' AND type = 'i' }} ``` - The query content contains both `content block` and `reference` paragraph blocks: ```c3Fs {{ SELECT * FROM blocks WHERE content LIKE '%content block%' AND content LIKE '%reference%' AND type = 'p') }} ``` - The query content contains heading blocks of both `content block` and `embed`, and the first 2 items are selected in descending order of update time: ```c3Fs {{ SELECT * FROM blocks WHERE content LIKE '%content block%' AND content LIKE '%embed%' AND type ='h' ORDER BY updated DESC LIMIT 2 }} ``` ### Case 1 The query contains paragraph blocks of both `In SiYuan` and `core concept` text, and excludes the current document (otherwise the paragraph block will also be included in the result set, because the current paragraph also contains these two texts. The following case is similar): ### Case 2 Query paragraph blocks that contain both tags `#Content block/Embed#` and `#Content block/Reference#`: ### Case 3 Sometimes we may need to randomly roam and display content blocks to facilitate review. ### Case 4 To query the unfinished task list items, you need to use the `markdown` field instead of the `content` field: --- # Conversion of Document and Heading ## Correspondence between Document and Heading The heading block and the document block have a natural correspondence, because: - Each document block has a name - Each heading block also has a name So we can convert between the document block and the heading block. In addition, because the content block is referenced based on id, the conversion process will not break the existing reference relationship. ## Convert Document block to Heading block In the doc tree, select the document that needs to be converted into a heading block, and then drag it to the position to be inserted in the editor tab. There are two situations here: 1. Place the document block on the existing heading block, and the document block will be inserted below as the level node of the heading block 2. Place the document block on a non-heading block, and the document block will be inserted as a child node of the heading block to which the block belongs After the document block is converted to a heading block: - The original document name will become the heading name - Logically, the document block is a first-level title, and the relative level will be changed according to the insertion position - Each heading level in the original document will be adjusted according to the insertion position - For the above situation 1: For example, if the original document contains the first, second, and third level headings, and the insertion position is a second-level heading, the heading block after the document block conversion will be a second-level heading. Level 3 headings will become Level 2, 3, and 4 headings - For the second case above: For example, the original document contains headings of level 1, 2, and 3, and the insertion position is a paragraph block under a level 2 heading. The heading block after the conversion of the document block will be a level 3 heading. Level 1, 2, and 3 headings will become Level 3, 4, and 5 headings ## Convert Heading block to Document block In the editor tab, select the heading block to be converted, press and hold the heading block icon, and then drag it to the folder to be placed in the doc tree. If you need to place it on the notebook root folder, drag the heading block icon to the top notebook icon row. After the heading block is converted to a document block: - The heading name will become the document name - If there are subtitles under the original heading block, the largest level of these subtitles will be used as the first level of the new document, and the remaining subtitles will be adjusted according to the relative level - For example, the original heading block contains three, four, and five levels of subtitles, and these subtitles will be converted into one, two, and three levels after being converted into a document block --- # Content Block Attribute ## Overview Attributes exist in the form of key-value pairs. We can enrich the connotation of the content block by setting attributes on the content block. Attributes are divided into built-in attributes and custom attributes. ## Built-in attributes | Property name | Description | |---|---| | name | Name of the content block | | alias | Alias of content block | | memo | Memo of the content block | | bookmark | Bookmark of content block | ## Custom attributes The user-defined attributes are set by the user through the `Block icon menu` -`Attribute`, and only English letters and Arabic numerals are allowed in the attribute name (such as `doing`, `7days`). After setting, SiYuan will automatically prefix the attribute name with `custom-` to distinguish built-in attributes from custom attributes. ## Using attributes There are two main usage scenarios for attributes: querying content blocks based on attributes and storing widget data. ### Query content blocks based on attributes For example, when we set the properties of `progress=30` and `priority=2` for the content block, we can query all content blocks with a progress of 30 and a priority of 2 through SQL: ```c3Fs SELECT * FROM blocks WHERE id IN ( SELECT block_id FROM attributes AS a WHERE (a.name ='custom-progress' AND a.value = '30') OR (a.name ='custom-priority' AND a.value = '2') GROUP BY block_id HAVING count(block_id) = 2 ); ``` ### Store widget data The widget can set the attributes through the interface, please refer to the development document for details. --- # Content Block --- # Theme ## Installation ### Manual 1. Get the theme from somewhere and unzip it 2. Settings - Appearance - Theme - Open the theme folder 3. Copy the theme to this folder 4. Restart, select the desired theme in Settings - Appearance - Theme ### Community Bazaar - In Settings - Appearance - Theme - Bazaar, browse online themes contributed by community developers - Choose the required theme to install or update online ## Development ### Step 1. Give your subject a nice name, such as `alice` 2. Settings - Appearance - Theme - Open theme folder 3. Create a new folder `alice` in the opened folder, and create new `theme.css` and `theme.json` files in `alice`The `theme.json` file is as follows: ```anNvbg== { "name": "midnight", "author": "Vanessa", "version": "1.0.0", "modes": ["dark"] } ``` `modes` is the appearance mode, divided into `dark` and `light`. Please modify the other fields as needed. 4. Open the `theme.css` file to start your coding journey 5. Restart, select the installed theme in Settings - Appearance - Theme ### Encoding - Familiar with [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) basic knowledge - Modify the color scheme in `:root{...}`. ⚠️ The variable items inherent in the official cannot be deleted - Continue to modify according to steps 1-4 in the figure - Copy and paste the modified content into `theme.css` and save - Check the `Disable cache` in `Network` and run `window.location.reload()` to see the final result In addition to modifying the style through theme.css, if theme.js exists in the theme folder, it will be automatically loaded when rendering the interface, so that some function-related customizations can be achieved through JavaScript code. Note: Do not modify the editor DOM, the blocks in the editor should pass the [Block API](https://github.com/siyuan-note/siyuan/blob/master/API.md#Blocks) to operate. ## Push to theme bazaar Please make sure that the root path of your theme repository contains at least the following files before listing ([repo example](https://github.com/88250/Comfortably-Numb)): - theme.css - theme.json (please make sure the JSON format is correct) - preview.png (please compress the image size within 512 KB) - README.md (please note the case) After confirmation, please [create a pull request](https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request) to the [Community Bazaar](https://github.com/siyuan-note/bazaar) repository and modify the themes.json file in it. This file is the index of all community theme repositories, the format is: ```anNvbg== { "repos": [ "username/reponame@commithash" ] } ``` Among them, `commithash`, please fill in the Git commit hash of the latest released version on your theme repository, please use the full hash value instead of the 7-digit short value. ### Update If the theme you developed has an updated version, please remember: - Update the version field in your theme.json - Create a Pull Request to the community bazaar --- # Icon ## Installation 1. Get the icon and unzip 2. Settings - Appearance - Icon - Open Icon Folder 3. Copy the icon to this directory 4. Restart, select the installed icon in Settings - Appearance - Icon ## Development ### Step 1. Give your icon a nice name, such as `alice` 2. Settings - Appearance - Icon - Open Icon Folder 3. Create a new folder `alice` in the opened folder, and create new `icon.js` and `icon.json` files in `alice` The `icon.json` file is as follows: ```anNvbg== { "name": "alice", "author": "Vanessa", "url": "https://github.com/Vanessa219", "version": "1.0.0" } ``` 4. Open the `icon.js` file and paste the completed icon 5. Restart, select the installed icon in Settings - Appearance - Icon ### Icon production - Use a browser to open the `` file in the icon folder - Make similar icons based on the icon name and shape - Go to [Iconfont](https://www.iconfont.cn) to search for your favorite icon and download the SVG format - Use vector graphics tools to make your own icons in SVG format - Go to [pngtosvg](https://www.pngtosvg.com/) to convert the picture to SVG format - Go to [IcoMoon App](https://icomoon.io/app/#/select) to make `` - Click on `` in the upper right corner to import the pictures made in the previous step - Select the icon and generate SVG - Modify the size and download - Modify the `` in `` to the icon name corresponding to `` - Replace the content in `` to the corresponding position in `` - Test - Replace `` in `` with `` ```aHRtbA== ``` - Refresh `` to see the final result - Open SiYuan and select the developed icon in Settings - Appearance - Icon to view ## Push to icon bazaar Please make sure that the root path of your icon repository contains at least the following files before listing: - icon.js - icon.json (please make sure the JSON format is correct) - preview.png (please compress the image size within 512 KB) - README.md (please note the case) After confirmation, please [create a pull request](https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request) to the [Community Bazaar](https://github.com/siyuan-note/bazaar) repository and modify the consi.json file in it. This file is the index of all community icon repositories, the format is: ```anNvbg== { "repos": [ "username/reponame@commithash" ] } ``` Among them, ``, please fill in the Git commit hash of the latest released version on your icon repository, please use the full hash value instead of the 7-digit short value. ### Update If the icon you developed has an updated version, please remember: - Update the version field in your icon.json - Create a Pull Request to the community bazaar --- # Custom Appearance --- # Formatting elements ## Inline elements - Please Start Here - [Hyperlink](https://ld246.com) - **Bold** - *Italic* - Underline - ~~Strikethrough~~ - ==Mark== - Superscript - Subscript - Keymap - Tag - `Inline Code` - **Color 1** **Color 2** **Color 3** **Color 4** **Color 5** **Color 6** **Color 7** **Color 8** **Color 9** **Color 10** **Color 11** **Color 12** **Color 13** **Style 1** **Style 2** - Trigger an emoji search by typing `:` followed by a letter 😄 😆 😵 😭 😰 😅 😢 😤 😍 😌👍 👎 💯 👏 🔔 🎁 ❓ 💣 ❤️ ☕️ 🌀 🙇 💋 🙏 💢 ## Pictures Support direct copy and paste or drag and upload. After uploading, you can adjust the size by dragging the sidebar. ## Super block Paragraph 1 Paragraph 2 Center Paragraph 3 Paragraph 4 Right ## Embed block ## Heading block ## Ordered, unordered, task list ### Unordered List - Java - Spring - IoC - AOP - Go - gofmt - Wide - Node.js - KoaExpress - Express ### Ordered List 1. Node.js 1. Express 2. Koa 3. Sails 2. Go 1. gofmt 2. Wide 3. Java 1. Latke 2. IDEA ### Task list - Release SiYuan - Book a dentist ## Blockquote > Note that it is not a content block ref, but a block quote (Blockquote). ## Code block If the language name is followed by ```, it can have the effect of syntax highlighting, for example: ### Demonstrate Go code highlighting ```Z28= package main import "fmt" func main() { fmt.Println("Hello, World") } ``` ### Demo Java highlighting ```amF2YQ== public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } ``` > Tip: Language names support the following: `ruby`, `python`, `js`, `html`, `erb`, `css`, `coffee`, `bash`, `json`, `yml`, ` xml` ... ## Table | header 1 | header 2 | |---|---| | cell 1 | cell 2 | | cell 3 | cell 4 | | cell 5 | cell 6 | ## HTML block  好 hǎo  世 shì  界 jiè
Hello World Note: The code in the HTML block will not be safely filtered when using it. Please confirm the code is safe before using it to avoid cross-site scripting (XSS). ## Horizontal rule --- ## Mathematical formula $$ \frac{1}{ \Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{ \frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} { 1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}}{1+\cdots}} } } $$ ## IFrame ## Video ## Audio ## Mind map ```bWluZG1hcA== - Tutorial - Grammar guidance - General content - Mention users - Emoji - Some emoji examples - Heading-Heading 3 - Heading 4 - Heading 5 - Heading 6 - Picture - Code block - Normal - Syntax highlighting support - Demonstrate Go code highlighting - Demo Java highlighting - Ordered, disordered, task list - Unordered list - Ordered list - task list - Form - Hide details - Paragraph - Link reference - Mathematical formula - Mind Map - Flow chart - Timing diagram - Gantt chart - Chart - Staff - Graphviz - Multimedia - Footnote - Shortcuts ``` Use Markdown list syntax to render the mind map. ## Flow chart ```bWVybWFpZA== graph TB c1-->a2 subgraph one a1-->a2 end subgraph two b1-->b2 end subgraph three c1-->c2 end ``` Please refer to [Mermaid](https://github.com/mermaid-js/mermaid) for the syntax. ## Timing diagram ```bWVybWFpZA== sequenceDiagram Alice->>John: Hello John, how are you? loop Every minute John-->>Alice: Great! end ``` Please refer to [Mermaid](https://github.com/mermaid-js/mermaid) for the syntax. ## Gantt chart ```bWVybWFpZA== gantt title A Gantt Diagram dateFormat YYYY-MM-DD section Section A task :a1, 2019-01-01, 30d Another task :after a1, 20d section Another Task in sec :2019-01-12, 12d another task: 24d``` Please refer to [Mermaid](https://github.com/mermaid-js/mermaid) for the syntax. ## Class diagram ```bWVybWFpZA== classDiagram Class01 <|-- AveryLongClass : Cool Class03 *-- Class04 Class05 o-- Class06 Class07 .. Class08 Class09 --> C2 : Where am i? Class09 --* C3 Class09 --|> Class07 Class07 : equals() Class07 : Object[] elementData Class01 : size() Class01 : int chimp Class01 : int gorilla Class08 <--> C2: Cool label``` Please refer to [Mermaid](https://github.com/mermaid-js/mermaid) for the syntax. ## User Journey Diagram ```bWVybWFpZA== journey title My working day section Go to work Make tea: 5: Me Go upstairs: 3: Me Do work: 1: Me, Cat section Go home Go downstairs: 5: Me Sit down: 5: Me``` Please refer to [Mermaid](https://github.com/mermaid-js/mermaid) for the syntax. ## Git graph ```bWVybWFpZA== gitGraph: options { "nodeSpacing": 150, "nodeRadius": 10 } end commit branch newbranch checkout newbranch commit commit checkout master commit commit merge newbranch``` Please refer to [Mermaid](https://github.com/mermaid-js/mermaid) for the syntax. ## Entity Relationship Diagram ```bWVybWFpZA== erDiagram CUSTOMER ||--o{ ORDER : places ORDER ||--|{ LINE-ITEM : contains CUSTOMER }|..|{ DELIVERY-ADDRESS : uses``` Please refer to [Mermaid](https://github.com/mermaid-js/mermaid) for the syntax. ## Chart ```ZWNoYXJ0cw== { "title": { "text": "Latest 30 days" }, "tooltip": { "trigger": "axis", "axisPointer": { "lineStyle": { "width": 0 } } }, "legend": { "data": ["Articles", "Users", "Replies"] }, "xAxis": [{ "type": "category", "boundaryGap": false, "data": ["2019-05-08","2019-05-09","2019-05-10","2019-05-11","2019-05-12","2019-05-13","2019-05-14","2019-05-15","2019-05-16","2019-05-17","2019-05-18","2019-05-19","2019-05-20","2019-05-21","2019-05-22","2019-05-23","2019-05-24","2019-05-25","2019-05-26","2019-05-27","2019-05-28","2019-05-29","2019-05-30","2019-05-31","2019-06-01","2019-06-02","2019-06-03","2019-06-04","2019-06-05","2019-06-06","2019-06-07"], "axisTick": { "show": false }, "axisLine": { "show": false } }], "yAxis": [{ "type": "value", "axisTick": { "show": false }, "axisLine": { "show": false }, "splitLine": { "lineStyle": { "color": "rgba(0, 0, 0, .38)", "type": "dashed" } } }], "series": [ { "name": "Articles", "type": "line", "smooth": true, "itemStyle": { "color": "#d23f31" }, "areaStyle": { "normal": {} }, "z": 3, "data": ["18","14","22","9","7","18","10","12","13","16","6","9","15","15","12","15","8","14","9","10","29","22","14","22","9","10","15","9","9","15","0"] }, { "name": "Users", "type": "line", "smooth": true, "itemStyle": { "color": "#f1e05a" }, "areaStyle": { "normal": {} }, "z": 2, "data": ["31","33","30","23","16","29","23","37","41","29","16","13","39","23","38","136","89","35","22","50","57","47","36","59","14","23","46","44","51","43","0"] }, { "name": "Replies", "type": "line", "smooth": true, "itemStyle": { "color": "#4285f4" }, "areaStyle": { "normal": {} }, "z": 1, "data": ["35","42","73","15","43","58","55","35","46","87","36","15","44","76","130","73","50","20","21","54","48","73","60","89","26","27","70","63","55","37","0"] } ] } ``` ## Staff ```YWJj X: 24 T: Clouds Thicken C: Paul Rosen S: Copyright 2005, Paul Rosen M: 6/8 L: 1/8 Q: 3/8=116 R: Creepy Jig K: Em |:"Em"EEE E2G|"C7"_B2A G2F|"Em"EEE E2G|\ "C7"_B2A "B7"=B3|"Em"EEE E2G| "C7"_B2A G2F|"Em"GFE "D (Bm7)"F2D|\ 1"Em"E3-E3:|2"Em"E3-E2B|:"Em"e2e gfe| "G"g2ab3|"Em"gfeg2e|"D"fedB2A|"Em"e2e gfe|\ "G"g2ab3|"Em"gfe"D"f2d|"Em"e3-e3:| ``` Please refer to [abcjs](https://github.com/paulrosen/abcjs) for the syntax. ## Graphviz ```Z3JhcGh2aXo= digraph finite_state_machine { rankdir=LR; size="8,5" node [shape = doublecircle]; S; node [shape = point ]; qi node [shape = circle]; qi -> S; S -> q1 [label = "a" ]; S -> S [label = "a" ]; q1 -> S [label = "a" ]; q1 -> q2 [label = "ddb" ]; q2 -> q1 [label = "b" ]; q2 -> q2 [label = "b" ]; }``` Please refer to [Graphviz](https://graphviz.org) for the syntax. ## Flowchart ```Zmxvd2NoYXJ0 st=>start: Start op=>operation: Your Operation cond=>condition: Yes or No? e=>end st->op->cond cond(yes)->e cond(no)->op ``` Please refer to [flowchart.js](https://github.com/adrai/flowchart.js) for the syntax. ## PlantUML ```cGxhbnR1bWw= @startuml component actor client node app database db db -> app app -> client @enduml ``` Please refer to [PlantUML](https://plantuml.com) for the syntax. --- # Editor - Editing and typesetting based on content blocks - List outline, support with or without sub-level indentation - Content block zoom, that is, each content block can be zoomed into focus - Dynamic loading, solving large document jams - Horizontal layout by dragging block icon --- # Type filtering ## Type field `type` - `d` Document block (Only search on the document name, will not search for the document containing content blocks) - `h` Heading block (Search only on the heading name, not the content blocks below the heading block) - `l` List block (including ordered list block, unordered list block and task list block) - `i` List item block - `c` Code block - `m` Mathematical formula block - `t` Table block - `b` Blockquote block - `s` Super block - `p` Paragraph block - `html` HTML block ## Subtype field `subtype` List block / List item block subtypes: - `o`:Ordered - `u`:Unordered - `t`:Task Heading subtypes: - `h1`: Level 1 - `h2`: Level 2 - `h3`: Level 3 - `h4`: Level 4 - `h5`: Level 5 - `h6`: Level 6 Other types of content blocks have no subtypes. --- # Database table ## Table `blocks` This table is used to store content block data. | Field | Description | |---|---| | id | Content block ID | | parent_id | Parent block ID, If the content block is a document block, this field is empty | | root_id | Root block ID, which is the document block ID | | hash | Summary checksum of the content | | box | Notebook ID | | path | The path of the document where the content block is located | | hpath | The path to the document where the human-readable content block is located | | name | Content block name | | alias | Content block alias | | memo | Content block memo | | content | Text with Markdown markers removed | | fcontent | The first child block text with Markdown markers removed | | markdown | Text with complete Markdown markers | | length | Length of `fcontent` | | type | Content block type, please refer to here | | subtype | Content block subtype, please refer to here | | ial | Inline attributes list, like `{: name="value"}` | | sort | For sorting, the smaller the value, the higher the sort | | created | Create time | | updated | Update time | ## Default values - If `LIMIT` is not specified, only the first 64 results will be returned at most, adjustable via Settings - Search - The number of search results displayed - `sort` field - Document block: `0` - Heading block: `5` - Paragraph block: `10` - Code block: `10` - Mathematical formula block: `10` - Table block: `10` - HTML block: `10` - List block: `20` - List item block: `20` - Blockquote block: `20` - Super block: `30` --- # Query syntax ## Overview Global search Ctrl+P supports advanced search through query syntax, in order to implement some logical operations, such as the query syntax that contains the keyword `foo` and does not contain the keyword `bar` is `foo NOT bar`. Before using the query syntax, let's have a general understanding of its composition: - String: composed of letters, numbers, etc. - Phrase: composed of strings - Query: composed of phrases, multiple queries can be combined into a new query through `AND`, `OR` and `NOT` Below we introduce their details respectively. ## Strings Strings can be specified in two ways: - Characters enclosed in English double quotes `"`. If `"` itself needs to be used, it can be escaped by SQL-style (plus a `"`), for example `"foo""bar"""` will hits `foo "bar"` - Consists of non `AND`, `OR` and `NOT` characters, and these characters must be: - All non-ASCII characters, or - Belongs to 52 uppercase and lowercase English characters (`A-Za-z`), or - Belongs to 10 ASCII numeric characters (`0-9`), or - Is an underscore `_`, or - Is the replacement character (ASCII 26) For strings that are not composed of other characters mentioned above, they must be wrapped with `"`, such as strings containing `-`, `*` and other symbols. ## Phrases Phrases consist of strings, which can be concatenated by `+`. A phrase is composed of some tokens in order, and these tokens are processed by the user's input text through the tokenizer. The tokenizer used by SiYuan is to make Chinese search easy to use (supports single-word search), so the implementation is based on word segmentation ([Tokenizer code](https://github.com/siyuan-note/sqlite-fts5-siyuan-tokenizer)), which means that each Chinese character or English letter will be split into a token. This has some effect on `+` concatenation, so it is recommended not to use `+` to combine multiple phrases if unsure. ## Queries A query consists of multiple phrases, which can be combined into a new query by the operators `AND`, `OR`, and `NOT`. | Operator | Function | |---|---| | ` AND ` | Matches if both query1 and query2 match | | ` OR ` | Matches if either query1 or query2 match | | ` NOT ` | Matches if query1 matches and query2 does not match | Use parentheses `()` to combine query priorities, for example: ```c3Fs -- Matches documents that contain at least one instance of either "one" or "two", but do not contain any instances of token "three". 'one OR two NOT three' -- Match all documents that contain the token "two" but not "three", or contain the token "one". 'one OR (two NOT three)' ``` Multiple phrases separated by spaces use `AND` by default, for example: ```c3Fs 'one two three' -- 'one AND two AND three' 'three "one two"' -- 'three AND "one two"' 'NEAR(one two) three' -- 'NEAR(one two) AND three' 'one OR two three' -- 'one OR two AND three' '(one OR two) three' -- Syntax error! 'func(one two)' -- Syntax error! ``` ## Technical implementation We implement global search through [SQLite FTS5](https://www.sqlite.org/fts5.html). The key part of the query statement generated by the system is roughly `MATCH '{content name alias memo}:" + query`, `query` is the user input part, for [column filter](https://www.sqlite.org/fts5 .html#fts5_column_filters) `{content name alias memo}:` is generated by Settings - Search - Attribute. After knowing these, we can implement the query embedding block through the query syntax, so that the query performance will be better: In addition to this, the API also supports querying using FTS. ### Case Sensitive If the Settings - Search - Case Sensitivity option is enabled, the search will be case-sensitive. By default, this option is disabled, that is, insensitive upper and lower case. Since the tokenizer is case-sensitive, we build two virtual tables to index separately: - `blocks_fts`: word segmentation by character - `blocks_fts_case_insensitive`: Convert English letters to lowercase participles The disadvantage of this is that it increases disk space usage and reduces indexing performance, but there is currently no better solution, so it can only be done first. In addition, Unicode case folding and diacritics are not supported, only English letters are supported ignoring case. If you have a better implementation, please let us know, thank you very much. --- # Advanced search --- # Storage The cloud storage space is `8G`, divided into three parts: - Synchronized data: Provided to the synchronization function, the data is encrypted - Backup data: Provided to the backup function, the data is encrypted - Asset file: Provided for copying to the Wechat MP, Zhihu and Yuque, etc., HTTPS CDN --- # Data Sync ## Overview Data synchronization refers to keeping the `workspace/data/` folder data consistent on multiple devices, including asset files, templates, widgets, and notebook data. ## How to use Open Settings - Cloud - Cloud sync and proceed through the synchronization setting wizard. 1. Set the end-to-end encryption password 2. Create or select a cloud synchronization directory. After selecting, the cloud synchronization directory will be used for data synchronization in the current workspace 3. Enable sync switch Please perform the above operations on the *main* device first, then select the same cloud sync directory on other devices and turn on the sync switch. If you want to switch, rename or remove the cloud sync directory, please turn off the sync switch on all devices before proceeding. ## Ignore files If you need to ignore some files during synchronization, please create or edit the text file `workspace/data/.siyuan/syncignore` on the file system, each line is configured with the relative path of the data folder, which means that the path of the file or folder is ignored and wildcard characters are supported. E.g: - `20210808180117-6v0mkxr/**/*`: Ignore the data/20210808180117-6v0mkxr notebook - `assets/*.pdf`: ignore PDF files under data/assets/ ## Working principle SiYuan performs corresponding operations by comparing the cloud data version and the local data version: - Skip if the version is equal - If the cloud version is greater than the local version, download the cloud data locally and decrypt it to the `workspace/data/` folder, and the local overwritten or deleted files will be moved to the `workspace/history/` folder - If the cloud version is less than the local version, scan for changes in `/workspace/data/`, then encrypt the changes and copy them to the folder `workspace/sync/`, and finally upload and overwrite the cloud data The version comparison is automatically performed at regular intervals. The time interval algorithm is described as follows: - After 30 seconds of data change, if there is no further change, a comparison will be made, and if it continues to change, it will be delayed by 30 seconds - If there is no data change, it will be incremented by 5 minutes, 8 minutes, 16 minutes, 32 minutes... ## Scenario example From the above working principle, we can know that SiYuan only supports alternate synchronization of data on multiple devices: after synchronization is completed on device A, synchronization is performed on device B. Simultaneous synchronization of multiple devices cannot be supported, so unexpected data overwriting will occur. ### Normal scene 1. Execute synchronization after editing on device A (by triggering synchronization automatically or manually), at this time, the cloud data will be overwritten by the data of device A, that is, the cloud and device A keep the same data 2. Execute synchronization on device B. At this time, the data of device B will be overwritten by the cloud data, that is, the cloud and devices A and B keep the same data 3. After editing on device B, perform synchronization again. At this time, the cloud data will be overwritten by device B data, that is, the cloud and device B keep the same data. 4. Execute synchronization on device A. At this time, the data of device A will be overwritten by the cloud data, that is, the cloud and devices A and B keep the same data In this scenario, the process of using synchronization is performed alternately on devices A and B, which can ensure that data synchronization is completed normally as expected. ### Override scene 1. Not syncing after editing on device A (for example, when there is no network and it is offline) 2. Not syncing after editing on device B 3. Perform synchronization on device A. At this time, the cloud data will be overwritten by the data of device A, that is, the cloud and device A keep the same data. 4. Perform a sync on device B, at which point there are three possible scenarios - Device B data skip synchronization because the version and cloud are the same - Device B data covers the cloud - Device B data is overwritten by the cloud In this scenario, the process of using synchronization is to edit offline on both devices, and then perform synchronization, so that the expected results of normal synchronization cannot be obtained. Even so, the data will not be lost, and the overwritten data can be retrieved through history. ## Note - Synchronization will not be triggered in the case of sudden disconnection such as sleep or shutdown, please manually click the synchronization button to synchronize - Before renaming or deleting the cloud directory, please turn off synchronization on all devices before editing or deleting - Do not use a third-party sync disk and SiYuan sync at the same time, it may cause data damage - Symbolic links will not be synchronized --- # Data Backup ## Backup Backup refers to encrypting and copying all files in the `workspace/data/` folder to the `workspace/backup/` folder. ### How to use 1. Open Settings - Cloud, configure End-to-end encryption password 2. Settings - Cloud - Local backup select Backup and upload, after the backup is completed, a popup will prompt whether to upload, select Confirm 3. After the upload is complete, there will be a copy of the same encrypted data as the local backup in the cloud ## Recovery Restoration refers to restoring the encrypted data in the `workspace/backup/` folder to the `workspace/data/` folder. ### How to use 1. Open Settings - Cloud, configure End-to-end encryption password 2. Settings - Cloud - Cloud backup Select Download and recover, after the download is complete, a pop-up will prompt whether to restore, select Confirm 3. After the recovery is complete, the application will be closed, and you can restart it manually ## Note - The backup data is stored in the `workspace/backup/` folder by default, and the location can be modified - Do not use a third-party synchronization disk to synchronize the folder, otherwise it may cause data damage - Without changing the password, the data is transferred incrementally - The password must be kept in mind, the data cannot be recovered without a password, and the password cannot be cleared or retrieved - After restoring from the backup, the current workspace data will be overwritten and cannot be restored. Please confirm before using the backup to restore --- # End-to-end Encryption ## Overview SiYuan will encrypt data before backup and synchronization, and the encrypted data can be safely transmitted and hosted over the network. - The encryption and decryption process is completely performed on the local device - The encryption algorithm is AES GCM, which is recognized as safe in the industry - The password set by the user is encrypted with the built-in key of the program and stored locally ## Password generation There are two methods to generate end-to-end encrypted passwords: 1. Automatic generation of algorithm based on user id 2. Based on user-defined password generation The differences between the two password generation methods are: - The id generation method is mainly for simplicity and convenience, but technically developers can decrypt data in the cloud - The main purpose of using a custom password is to be more secure (unless you know the password or brute force, it cannot be decrypted), but the operation is relatively troublesome and the password must be remembered ## Note Once the password generation method is selected: - Need to keep the same build method on all devices - You cannot switch after selecting the generation method - If you use a custom password, please keep in mind ## Encrypted content data/.siyuan folder and sub-files conf.json, syncignore, these data are configuration and metadata required for synchronization, so they will not be encrypted. In addition to this, all data in the data folder will be encrypted. The specific encrypted content is: - Folder name and file name (such as the file name of .sy files and assets files) - file content --- # Assets Serving SiYuan provides cloud assets serving, which is mainly used to copy documents and asset files to platforms such as WeChat MP, Zhihu and Yuque. The editors of these platforms will automatically pull resource files to their platforms when pasting. ## How to use 1. In the upper right corner of the document, select ... in the More menu and select Upload asset files to cloud 2. Select Export Preview in Toogle Mode 3. Click Copy to Wechat MP, Copy to Zhihu or Copy to Yuque 4. Paste into the target platform editor If you need to delete the files in the cloud assets serving, please go to [LianDi - Settings - File - Note](https://ld246.com/settings/file?type=3) to operate. After deletion, the cloud storage space occupied by the file will be released immediately, but the CDN cache cleaning may not take effect in time, which will cause the file URL to remain accessible until the CDN cache expires automatically after 30 days. ## Note - Please do not directly use the external link address provided by cloud assets on other platforms. This address is unstable and may affect the availability due to the domain name change - Please do not upload illegal or sensitive files. The uploaded files will be reviewed through services provided by third parties (pornography, violent terrorism, sensitive people, etc.). If a user is found to upload illegal files, the user account will be permanently banned, and the corresponding legal responsibility will be assumed --- # Limitations - During synchronization or backup, single file transfer larger than 100MB is not supported - Supports the creation of up to 7 cloud synchronization directories - The initial total size of cloud storage space is `8G` - After the paid subscription expires, the cloud storage will be completely deleted --- # Cloud --- # Bookmark and Tag ## Bookmark If you need to "favorite" content blocks, please open the attribute panel through the block icon menu, and then you can set bookmarks in the attribute panel. The built-in bookmark label are ✨💡️⏳, you can create other text as the bookmark label. All favorite content blocks will be listed in the bookmark tab (Alt 3 / ⌘ 3). If you want to cancel the collection, select Delete in the drop-down menu of the content block ID. ## Tag The tag is used to mark the block in the content block. The syntax is to wrap the tag identifier with two `#` in the first and one after the other, like this `#Tag#`. Tag support hierarchical levels, so that content blocks can be sorted more easily. Use `/` to separate different levels, like this `#A/B/C#`. All tagged content blocks will be listed in the tag tab (Alt 4 / ⌘ 4). If you need to cancel the tag, just delete the tag in the content block. --- # Kernel parameter ### `--workspace` Used to specify the workspace folder path, the default value when not specified is `~/Documents/SiYuan/`. ### `--wd` Kernel working directory path, automatically obtained according to the kernel executable file entry if it is not specified. ### `--resident` After specifying with `--resident=true`, the kernel will be resident in memory, the default is `true`. After set to `false`, the list of active sessions will be checked every 30 seconds, and the kernel process will be exited if there are no active sessions. ### `--readonly` After specifying with `--readonly=true`, the kernel will run in read-only mode and all write operations will be prohibited. ### `--accessAuthCode` Used to specify the browser access authentication password, which will overwrite the authCode in conf.json after setting. ### `--ssl` After using `--ssl=true`, https and wss protocols will be used for serving. ### `--lang` Using `--lang=zh_CN` will use Simplified Chinese to initialize the appearance language, the default is `en_US`. Currently available values: `zh_CN`, `zh_CHT`, `en_US` and `fr_FR`. --- # Assets ## Overview Attachments inserted through the editor will be regarded as asset files and will be placed in the workspace data/assets folder by default. ## Insert picture In the editor, you can directly paste the copied picture from the system clipboard, or you can also insert pictures by dragging and dropping picture files into the editor. If you specify a title for a picture, then the title will be rendered below the image as a legend. ## Cleanup unreferenced assets "Reference" refers to the link `[foo](bar)` through Markdown, the image syntax `![foo](bar)` or the attribute `src` of HTML tags (such as ``, `