Home Web Front-end HTML Tutorial tinymce and prism implement highlighted code and Chinese configuration method process

tinymce and prism implement highlighted code and Chinese configuration method process

Jul 25, 2018 am 09:32 AM

This article introduces to you the implementation of code highlighting and Chinese configuration of tinymce and prism. It analyzes this problem in detail through specific examples. Friends in need can refer to it.

Brief introduction: TinyMCE is a lightweight browser-based WYSIWYG editor written in JavaScript. It has very good support for IE6 and Firefox1.5. The functions are powerful and the function configuration is flexible and simple. Another feature is that the loading speed is very fast. The most important thing is that TinyMCE is a free software released under the LGPL license. You can use it for commercial applications. Enough said. If you want to know more about Baidu, let’s get to the point.

1. Edit page configuration

1. First we need to reference the web page style control file and script language editing file (the first two are tinymce script files, and the last two are prism highlight files )

1

2

3

4

1 <script type="text/javascript" src="tinymce.min.js"></script>

2 <script type="text/javascript" src="jquery.tinymce.min.js"></script>

3 <link href="prism.css" rel="stylesheet" />

4 <script src="prism.js"></script>

Copy after login

2. Design our text in the body

1

1 <textarea name="content" style="width:100%"></textarea>

Copy after login

3. Initialize the text in js

(1) tinymce.init configures and initializes tinymce

(2) selector: "textarea" is specified according to your selector. Here is textarea, which can be bound to id (#···) or class (.····)

(3) plugins fill in the name of the plug-in to be used

(4) toolbar sets the toolbar to specify the display plug-in, here I show three toolbars

(5) menubar disables the menu bar Template

(6) toolbar_items_size toolbar label size is set to small

(7) style_formats is the default style initialized, this can be adjusted according to your own preferences

(8) templates template, The template in toolbar3 automatically appends the value content to the text box after selecting the title

(9) language: 'zh_CN' The language itself defaults to English, and the language specified here is Chinese

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

<script type="text/javascript">

    tinymce.init({

        selector: "textarea",

        plugins: [

            "advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",

            "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",

            "table contextmenu directionality emoticons template textcolor paste fullpage textcolor codesample"

        ],

  

        toolbar1: "undo redo | cut copy paste | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",

        toolbar2: " searchreplace | bullist numlist | outdent indent blockquote | link unlink anchor image media code codesample | inserttime preview | forecolor backcolor",

        toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",

  

        menubar: false,

        toolbar_items_size: &#39;small&#39;,

  

        style_formats: [

            {title: &#39;Bold text&#39;, inline: &#39;b&#39;},

            {title: &#39;Red text&#39;, inline: &#39;span&#39;, styles: {color: &#39;#ff0000&#39;}},

            {title: &#39;Red header&#39;, block: &#39;h1&#39;, styles: {color: &#39;#ff0000&#39;}},

            {title: &#39;Example 1&#39;, inline: &#39;span&#39;, classes: &#39;example1&#39;},

            {title: &#39;Example 2&#39;, inline: &#39;span&#39;, classes: &#39;example2&#39;},

            {title: &#39;Table styles&#39;},

            {title: &#39;Table row 1&#39;, selector: &#39;tr&#39;, classes: &#39;tablerow1&#39;}

        ],

  

        templates: [

            {title: &#39;Test template 1&#39;, content: &#39;Test 1&#39;},

            {title: &#39;Test template 2&#39;, content: &#39;Test 2&#39;}

        ],

        language:&#39;zh_CN&#39;

    });</script>

Copy after login

In addition, when we use codesample Inserting will generate the tinymce and prism implement highlighted code and Chinese configuration method process

(4) Assignment and setting value operations

1

2

3

1 var context=tinyMCE.activeEditor.getContent();//进行值得获取

3 tinyMCE.activeEditor.setContent("你的数据");//进行值得获取

Copy after login

2. Display page related configuration

1. Reference web page style control file and script language editing file (two highlights Display script)

1

2

1 <link href="prism.css" rel="stylesheet" />

2 <script src="prism.js"></script>

Copy after login

2. Just take out the value saved by your editor and display it on the page.

Related recommendations:

How to briefly describe the basic structure of html (with code)

What are the structural elements of HTML? Summary of various structural elements in HTML (plain text)

The above is the detailed content of tinymce and prism implement highlighted code and Chinese configuration method process. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

See all articles