平台开发中,欢迎参与测试。你可以在 QQ群:1046115671 中与我们交流,或是直接在社区发帖

Code Block

Go back to the list of Blocks

Just like the Posting Source Code feature works in the classic editor, with the Code Block you can add formatted code for others to view.

Code Blockexample:

if ( condition ) { action1(); action2();} elseif ( condition2 && condition3 ) { action3(); action4();} else { defaultaction();}

In order to add a Code Block, click on the add block button and select the Code Block.

You can also type “/code” and hit enter in a new paragraph block to add one quickly.

Detailed instructions on adding blocks can be found here.

Block Toolbar

Every block comes with unique toolbar icons and block specific user controls that allow you to manipulate the block right in the editor.

TheCode Block shows standard three buttons:

  • Change block type or style
  • Moving handles
  • 更多选项

Change block type or style

You can transform the Code Block into the Custom HTML Block,Preformatted Block, or Group. The Group would give you the ability to change the background color around the Code Block.

Editor view of Code Block as a group with Color settingscontrols

Moving handles

The up and down arrow icons can be used to shift a block up and down in your document.

Detailed instructions on moving a block within the editor can be found here.

More Options

Hide Block Settings

TheHide Block Settings option hides (or shows) the Block Setting panel in the editor’s sidebar.

Copy

Copy can be used to copy a selected block and then you can paste it wherever you want in the editor.

Duplicate

Duplicate can be used to duplicate selected block.

Insert Before

Insert a new block before the selected block(s).

Insert After

Insert a new block after the selected block(s).

Move To

If you select Move To, you will get a blue line inside your content, you can then use the arrows to move that line up and down to where you want the selected content to be moved into, hitting return on your keyboard at that point moves the block to that position.

Edit as HTML

TheEdit as HTML option allows you to modify the HTML code of the embed block.

Add to Reusable blocks

Using the Add to Reusable blocks option lets you add the selected block to a list of reusable blocks, so you can use them on other posts or pages as well.

Group

Select the Group option if you want to create a group of blocks and treat them as a unit. You can for instance add a common background color or other blocks to the group.

Remove Block

With the Remove Block option, you can delete the selected block from your content.

区块设置

Every block has specific options in the editor sidebar in addition to the options found in the block toolbar. If you do not see the sidebar, simply click the ‘cog’ icon next to the Publish button.

Typography

Typography gives you the option to define the font size of your Code Block’s contents. The font size is how large the characters are displayed on a screen. The editor comes with five font size options by default and a custom font size option, where you can type in any size you want.

Advanced

TheAdvanced tab lets you add HTML anchor and CSS class(es) to your block.

HTML anchor allows you to make a unique web address for a particular Code Block. Then, you’ll be able to link directly to a Code Block of your page.

TheAdditional CSS class(es) lets you add CSS class(es) to your block, allowing you to write custom CSS and style the block as you see fit.

Changelog

  • Updated 2021-02-27
    • Added Typography option
  • Updated 2020-09-13
    • Screenshots and video as per LitePress 5.5
    • Added feature changes in Block Toolbar
    • Added feature changes in Block Settings
  • Created 2019-03-07