Typewriter effect display method for streaming data
By configuring the big model interface and introducing the markdown-it dependency package, combining prismjs and escape-html processing code highlighting, markdownParse component is created, and the front-end typewriter effect display of streaming data is solved, solving the performance bottlenecks in large-scale data processing and Rendering speed issues improve user experience and page rendering speed.
Patent Information
- Application Number
- CN202411263219.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-10
- Publication Date
- 2024-11-22
AI Technical Summary
The existing technology has performance bottlenecks when processing large-scale data. The traditional HTTP protocol one-way connection leads to large network overhead and delayed data processing. Visual effect displays slow page rendering speed when processing large amounts of data, which affects the user experience.
By configuring the big model interface to realize streaming data return, the markdown-it dependency package is introduced to translate the markdown text into HTML in real time, the code highlighting is used using prismjs and escape-html, and the markdownParse component is created to realize the front-end typewriter effect display, and the text content is dynamically adjusted. and style.
It improves data return efficiency, improves page rendering speed, enhances code readability and operability, realizes dynamic display effect, and improves user experience.
Smart Images

Figure CN119003760A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of typewriters, and in particular to a method for displaying typewriter effects of streaming data. Background Art
[0002] 1) Background introduction of related technologies: With the development of the Internet, front-end development technology has become an important part of modern software development. Front-end development is mainly responsible for the design and implementation of user interfaces, including the layout, style, and interaction methods of web pages. At the same time, data processing technology is also constantly developing, and various big data processing technologies and algorithms are widely used in data analysis and processing. In addition, visual effect display technology is also constantly improving, and various dynamic effects and interactive designs are widely used in user experience design.
[0003] 2) Solutions of existing technologies: In existing technologies, front-end development mainly implements the design and implementation of user interfaces by writing languages such as HTML, CSS and JavaScript. At the same time, the back-end server sends data to the front-end through the HTTP protocol, and the front-end then parses the data to dynamically update the page. In terms of data processing, various big data processing technologies and algorithms are usually used to clean, integrate and analyze data. In terms of visual effects display, technologies such as CSS3, JavaScript and Canvas are usually used to achieve various dynamic effects and interactive designs.
[0004] 3) Problems with existing technologies: However, existing technologies often encounter performance bottlenecks when processing large-scale data. This is because the traditional HTTP protocol is one-way, and each request needs to re-establish a connection, which results in a large amount of network overhead. At the same time, existing data processing technologies and algorithms often cannot meet the needs of real-time processing, which results in delayed display of data. In addition, although existing visual effect display technologies can achieve various dynamic effects and interactive designs, when processing large amounts of data, they may cause the page rendering speed to slow down, affecting the user experience. Summary of the invention
[0005] In view of the above problems, the present invention is proposed to provide a typewriter effect display method for streaming data that overcomes the above problems or at least partially solves the above problems.
[0006] According to one aspect of the present invention, a method for displaying streaming data in a typewriter effect is provided, and the method for displaying streaming data in a typewriter effect comprises:
[0007] Step S1: configure the large model interface;
[0008] Step S2: Introduce the markdown-it dependency package into the front-end project to translate the markdown text into HTML language in real time;
[0009] Step S3: The system uses prismjs and escape-html to perform code highlighting, and uses the highlight function to adapt to the highlighting requirements of multiple programming languages;
[0010] Step S4: Create a component named "markdownParse" in the project to realize the front-end typewriter effect display;
[0011] Step S5: Run the project and see the real-time front-end typewriter effect display on the page.
[0012] Optionally, the step S1: configuring the large model interface specifically includes: setting the frequency of returning data to 10 times per second, and the amount of data returned each time is 100KB.
[0013] Optionally, the step S2: introducing the markdown-it dependency package in the front-end project to translate the markdown text into HTML language in real time specifically includes:
[0014] Introduce the markdown-it dependency package in the front-end project to translate the markdown text into HTML language in real time;
[0015] The specific operation is that the system initializes a MarkdownIt instance and sets various options according to the configuration items passed in;
[0016] The system uses a variety of plug-ins to enhance the functionality of Markdown;
[0017] The system uses custom plugins to handle HTML blocks, images, paragraphs, line numbers, and code block wrapping;
[0018] All settings and plugins work together to enable Markdown content to be rendered into high-quality HTML in real time.
[0019] Optionally, the various options set according to the passed-in configuration items specifically include: whether to support line breaks, whether to allow HTML tags, code highlighting, language prefixes, link resolution, quotation mark style, typesetting optimization and XHTML output.
[0020] Optionally, the system uses a variety of plug-ins to enhance the functionality of Markdown, specifically including: support for abbreviations, anchors, definition lists, footnotes, inserted text, marked text, subscripts, superscripts, and task lists.
[0021] Optionally, the step S3: the system uses prismjs and escape-html to perform code highlighting, and uses the highlight function to adapt to the highlighting requirements of multiple programming languages, specifically including:
[0022] The system uses prismjs and escape-html for code highlighting, and uses the highlight function to adapt to the highlighting requirements of different programming languages;
[0023] Depending on the programming language, the system will automatically adjust the code display style to ensure that code blocks in different languages can be correctly highlighted;
[0024] The system also provides a function to add a copy button on the code block, so that users can easily copy the code by clicking the button;
[0025] In the specific implementation, the system searches for the copy buttons of all code blocks after the page is loaded, and binds click events to the buttons. When the user clicks the button, the system copies the corresponding code block content to the clipboard and displays a prompt message indicating that the copy is successful.
[0026] Optionally, the step S4: creating a component named "markdownParse" in the project to implement the front-end typewriter effect display specifically includes:
[0027] Define a method called "render" in the component, which accepts a string parameter;
[0028] Get the corresponding markdown data by calling the large model interface, then translate the markdown data into HTML language through the markdown-it dependency package, and finally render the corresponding effect on the page.
[0029] Optionally, the step S5: running the project and seeing the real-time front-end typewriter effect display on the page specifically includes:
[0030] The system controls the display speed and effect of text by defining CSS animations, and dynamically adjusts the text content in JavaScript to present it gradually;
[0031] The system adjusts typing speed and style as needed to accommodate a variety of usage scenarios and user needs.
[0032] The present invention provides a method for displaying typewriter effects of streaming data, the method comprising: step S1: configuring a large model interface; step S2: introducing a markdown-it dependency package in a front-end project, for translating markdown text into HTML language in real time; step S3: the system uses prismjs and escape-html to perform code highlighting, and uses highlight functions to adapt to the highlighting requirements of multiple programming languages; step S4: creating a component named "markdownParse" in the project, for realizing front-end typewriter effect display; step S5: running the project, and seeing the real-time front-end typewriter effect display on the page. The front-end typewriter effect display of streaming return data of the front-end large model interface is realized, and the user experience is improved.
[0033] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0035] Figure 1 A flowchart of a method for displaying typewriter effect of streaming data provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0036] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0037] The terms "comprises" and "having" and any variations thereof in the description embodiments, claims and drawings of the present invention are intended to cover non-exclusive inclusions, for example, including a series of steps or units.
[0038] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments.
[0039] like Figure 1As shown, a method for displaying streaming data in a typewriter effect includes:
[0040] Step 1: Configure the large model interface, set the frequency of returning data to 10 times per second, and the amount of data returned each time to 100KB. This can ensure the streaming return of data, avoid the problem of HTTP returning data too slowly at one time, reduce the time the page needs to wait for the interface, and improve the user experience.
[0041] Step 2: Introduce the markdown-it dependency package in the front-end project, which can help us translate markdown text into HTML language in real time. The specific operation is that the system initializes a MarkdownIt instance and sets various options according to the passed in configuration items, such as whether to support line breaks, whether to allow HTML tags, code highlighting, language prefixes, link parsing, quotation mark style, typesetting optimization, and XHTML output. Then, the system uses a variety of plug-ins to enhance the functionality of Markdown, including support for abbreviations, anchors, definition lists, footnotes, inserted text, marked text, subscripts, superscripts, and task lists. In addition, the system also uses custom plug-ins to handle HTML blocks, images, paragraphs, line numbers, and code block packaging. All these settings and plug-ins work together to enable Markdown content to be rendered as high-quality HTML in real time.
[0042] Step 3: The system uses prismjs and escape-html to highlight the code, and uses the highlight function to adapt to the highlighting requirements of different programming languages. Depending on the programming language, the system will automatically adjust the display style of the code to ensure that code blocks in different languages can be correctly highlighted. The system also provides a function to add a copy button to the code block, and users can easily copy the code by clicking the button. In the specific implementation, the system searches for the copy buttons of all code blocks after the page is loaded, and binds click events to these buttons. When the user clicks the button, the system will copy the corresponding code block content to the clipboard and display a prompt message that the copy is successful.
[0043] Step 4: Create a component named "markdownParse" in the project. This component is mainly used to realize the front-end typewriter effect display. The specific implementation method is to define a method named "render" in the component. This method accepts a string parameter, and then obtains the corresponding markdown data by calling the large model interface in step 1. Then, the markdown data is translated into HTML language through the markdown-it dependency package in step 2, and finally the corresponding effect is rendered on the page.
[0044] Step 5: Run the project and you can see the real-time front-end typewriter effect display on the page. The system controls the display speed and effect of the text by defining CSS animations, and dynamically adjusts the text content in JavaScript to make it appear gradually. The system can also adjust the typing speed and style as needed to adapt to different usage scenarios and user needs.
[0045] Beneficial effects: 1) Improve data return efficiency: Traditional HTTP requests that return data at one time may result in long waiting time and poor user experience. This technical solution adopts a streaming data return method, returning streaming Markdown data through a large model interface, which can avoid the delay problem caused by returning data at one time, thereby reducing page waiting time and improving user experience.
[0046] 2) Improve page rendering speed: By using the `markdown-it` dependency package, the front-end can translate Markdown text into HTML in real time. This method can not only display the content of the markup language in real time, but also significantly improve the page rendering speed, avoiding the impact of rendering delay on user experience.
[0047] 3) Enhance code readability and operability: Support syntax highlighting, code block copy and paste and other functions for different programming languages, so that users can more conveniently view and operate markup language content, improving the user experience.
[0048] 4) Realize dynamic display effects: Through the front-end typewriter effect display technology, the page is made more beautiful and the user experience is further improved.
[0049] The above specific implementation methods further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above are only specific implementation methods of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for displaying streaming data in a typewriter effect, characterized in that: The typewriter effect display method comprises: Step S1: configure the large model interface; Step S2: Introduce the markdown-it dependency package into the front-end project to translate the markdown text into HTML language in real time; Step S3: The system uses prismjs and escape-html to perform code highlighting, and uses the highlight function to adapt to the highlighting requirements of multiple programming languages; Step S4: Create a component named "markdownParse" in the project to realize the front-end typewriter effect display; Step S5: Run the project and see the real-time front-end typewriter effect display on the page.
2. A method for displaying typewriter effect of streaming data according to claim 1, characterized in that: The step S1: configuring the large model interface specifically includes: setting the frequency of returning data to 10 times per second, and the amount of data returned each time is 100KB.
3. The method for displaying typewriter effect of streaming data according to claim 1, characterized in that: The step S2: introducing the markdown-it dependency package in the front-end project to translate the markdown text into HTML language in real time specifically includes: Introduce the markdown-it dependency package in the front-end project to translate the markdown text into HTML language in real time; The specific operation is that the system initializes a MarkdownIt instance and sets various options according to the configuration items passed in; The system uses a variety of plug-ins to enhance the functionality of Markdown; The system uses custom plugins to handle HTML blocks, images, paragraphs, line numbers, and code block wrapping; All settings and plugins work together to enable Markdown content to be rendered into high-quality HTML in real time.
4. A method for displaying typewriter effect of streaming data according to claim 3, characterized in that: The various options set according to the passed-in configuration items specifically include: whether to support line breaks, whether to allow HTML tags, code highlighting, language prefixes, link resolution, quotation mark style, typesetting optimization and XHTML output.
5. The method for displaying typewriter effect of streaming data according to claim 3, characterized in that: The system uses a variety of plug-ins to enhance the functions of Markdown, including: supporting abbreviations, anchors, definition lists, footnotes, inserted text, marked text, subscripts, superscripts and task lists.
6. A method for displaying typewriter effect of streaming data according to claim 1, characterized in that: Step S3: The system uses prismjs and escape-html to perform code highlighting, and uses the highlight function to adapt to the highlighting requirements of multiple programming languages, specifically including: The system uses prismjs and escape-html for code highlighting, and uses the highlight function to adapt to the highlighting requirements of different programming languages; Depending on the programming language, the system will automatically adjust the code display style to ensure that code blocks in different languages can be correctly highlighted; The system also provides a function to add a copy button on the code block, so that users can easily copy the code by clicking the button; In the specific implementation, the system searches for the copy buttons of all code blocks after the page is loaded, and binds click events to the buttons. When the user clicks the button, the system copies the corresponding code block content to the clipboard and displays a prompt message indicating that the copy is successful.
7. A method for displaying typewriter effect of streaming data according to claim 1, characterized in that: Step S4: Create a component named "markdownParse" in the project to implement the front-end typewriter effect display, specifically including: Define a method called "render" in the component, which accepts a string parameter; Get the corresponding markdown data by calling the large model interface, then translate the markdown data into HTML language through the markdown-it dependency package, and finally render the corresponding effect on the page.
8. A method for displaying typewriter effect of streaming data according to claim 1, characterized in that: The step S5: running the project and seeing the real-time front-end typewriter effect display on the page specifically includes: The system controls the display speed and effect of text by defining CSS animations, and dynamically adjusts the text content in JavaScript to present it gradually; The system adjusts typing speed and style as needed to accommodate a variety of usage scenarios and user needs.
Citation Information
Patent Citations
Front-end code snippet dynamic rendering method and system suitable for multiple framework languages
CN113805874A
Generative content display method and device, electronic equipment and storage medium
CN117407468A
Intelligent Chat question and answer stream typewriting output method and system implemented by pure front end
CN117743552A
Method for analyzing Markdown containing Vue component based on Webpack
CN117950666A
Method for reading streaming Markdown text and tracking and displaying reading progress
CN118280342A
