Linux 软件免费装
Banner图

Pastacode

开发者 willybahuaud
juliobox
更新时间 2022年11月17日 00:21
捐献地址: 去捐款
PHP版本: 3.1 及以上
WordPress版本: 6.1.1
版权: GPLv2 or later

标签

html embed php CSS block code comment Formatting bbPress codemirror syntax highlight github bitbucket sourcecode prismjs gist

下载

3.0.1 3.0 1.2.1 1.3 1.3.1 1.4 1.4.1 1.5 1.5.1 1.6 1.7 2.0 2.1

详情介绍:

With Pastacode, you can easily add code into your posts with the awesome PrismJs coloration library. You can insert source code into the post editor, wrinting it directly in the editor (using a gutenberg bloc or classic editor), from a file, or from webservices like GitHub, Gitlab, Gist, Pastebin, BitBucket or BitBucket snippets. Webservices responses are cached in order to avoid too many HTTP requests. It also work in comments and bbPress topics and replies. Don't worry about posts updates while upgrading codes! Pastacode allows to enhance your snippets using PrismJs plugins (highlightning lines, link functions...).

安装:

  1. Unzip Pastacode into your plugin folder
  2. Go to Pastacode settings, and configure your color scheme and cache expiration
  3. Host your snippets on repositories (or localy)
  4. To use:
  5. With the block editor, use the Pastacode block
  6. With classic-editor, use Past'a code button to embed your source code into articles

屏幕截图:

  • Edit your code with the Pastacode block
  • How it's renderer in editor (highlighted by Prism)
  • You can import a snippets hosted on many providers (gitlab, github…)
  • If you don't use block editor, you can use another UI, base on a tinyMCE plugin (work in the classic block, or with classic editor)
  • Here the Treeview lang, to share directory structure

常见问题:

Which programming languages are available?

For more information, please visit Pastacode Wiki

  • HTML
  • CSS
  • JavaScript
  • PHP
  • C
  • C#
  • C++
  • Java
  • Sass
  • Python
  • SQL
  • Ruby
  • CoffeeScript
  • Bash
  • Apache
  • Less
  • HAML
  • Git command line
  • Haskell
  • Markdown
  • Typescript
  • Treeview (directory structure)
If you use another syntax highligther plugins, migration scripts are available :)

What is the Treeview language?

You can use it to display a directory structure. Use pipes, backticks and hyphens like this: root_folder/ |-- a first folder/ | |-- holidays.mov | |-- javascript-file.js | `-- some_picture.jpg |-- documents/ | |-- spreadsheet.xls | |-- manual.pdf | |-- document.docx | `-- presentation.ppt | `-- test `-- README.md

How to setup a custom cache expiration ?

Paste these lines into your functions.php theme file: add_filter( 'option_pastacode_cache_duration', 'my_pastacode_cache_duration' ); function my_pastacode_cache_duration( $duration ) { $duration = DAY_IN_SECOND*3; // 3 days return $duration; }

How to change the color scheme ?

7 different color schemes are included, you can switch theme under Settings > Pastacode. You can also build yours: Paste these lines into your functions.php theme file: add_action( 'wp_enqueue_scripts', 'custom_enqueue_script', 11 ); function custom_enqueue_script() { $urlofmynewscheme = get_stylesheet_directory_uri() . '/prism-okaida-willy.css'; //this is an example wp_deregister_style( 'prismcss' ); wp_register_style( 'prismcss', $urlofmynewscheme, false, '1', 'all' ); } Get inspired of the default scheme to build your schemes

How to filter supported languages ?

Paste these lines into your functions.php theme file: //If you just want php, html, css and javascript support add_filter( 'pastacode_langs', '_pastacode_langs' ); function _pastacode_langs( $langs ) { $langs = array( 'php' => 'PHP', 'markup' => 'HTML', 'css' => 'CSS', 'javascript' => 'JavaScript', ); return $langs; }

Ajax compatibility

To enable Pastacode on ajax based websites, it need two steps:

  1. Turn on Legacy support in the settings panel
  2. Paste this line into your functions.php theme file: add_filter( 'pastacode_ajax', '__return_true' );
  3. After each change on your DOM, you will have to run this javascript function: Prism.highlightAll();

How to add a new provider ?

Paste these lines into your functions.php theme file: ``` //Take WordPress SVN, for example //register a provider add_filter( 'pastacode_services', '_pastacode_services' ); function _pastacode_services( $services ) { $services['wordpress'] = 'core.svn.wordpress.org'; return $services; } //Define pastabox lightbox inputs add_action( 'pastacode_fields', '_pastacode_fields' ); function _pastacode_fields( $fields ) { $fields['wordpress'] = array( // 'wordpress' or 'whatever' 'classes' => array( 'wordpress' ), // same value as the key 'label' => sprintf( __('File path relative to %s', 'pastacode'), 'http://core.svn.wordpress.org/' ), 'placeholder' =>'trunk/wp-config-sample.php', //if placeholder isn't defined, it will be a textarea 'name' => 'path_id' //these value return shortcode attribute (path_id, repos, name, user, version) ); $fields['pastacode-lines']['classes'][] = 'wordpress'; // Add ability to select lines $fields['pastacode-highlight']['classes'][] = 'wordpress'; // Add ability to highlight somes return $fields; } //Build the function to retrieve the code // "pastacode_wordpress" hook name (1st param) = "pastacode_" + "wordpress" or "whatever" add_action( 'pastacode_wordpress', '_pastacode_wordpress', 10, 2 ); function _pastacode_wordpress( $source, $atts ) { extract( $atts ); if( $path_id ) { $req = wp_sprintf( 'http://core.svn.wordpress.org/%s', str_replace( 'http://core.svn.wordpress.org/', '', $path_id ) ); $code = wp_remote_get( $req ); if( ! is_wp_error( $code ) && 200 == wp_remote_retrieve_response_code( $code ) ) { $data = wp_remote_retrieve_body( $code ); $source[ 'url' ] = $req; //url to view source $source[ 'name' ] = basename( $req ); //filename $source[ 'code' ] = esc_html( $data ); //the code !! //$source[ 'raw' ] contain raw source code. But there are no raw source code delivered by Wordpress SVN } } return $source; } ``` Do not add you root website!! A contributor can add the shortcode to point your "wp-config.php" to read it!!

更新日志:

3.0 2.1 2.0 1.8 1.7 1.6 1.5.1 1.5 1.4.2 1.4.1 1.4 1.3 1.2.1 1.2 1.1 1.0