Skip to content

Feature proposal: give the code tag a language-codeType class #1019

@LincZero

Description

@LincZero

Clear and concise description of the problem

It can very effectively optimize the copying results of code blocks copied from the article (without clicking the copy button).

Suggested solution

give the code tag a language-codeType class

Alternative

No response

Additional context

Here I provide a partial excerpt and translation of an article I wrote to describe the necessity of this requirement:



A discussion: Optimization for article copying and pasting

Let's discuss the code block first

Generally, code blocks provide a copy button, through which you can easily copy. But sometimes when we want to take notes, we tend to copy along with the article parts above and below the code blocks. However, different websites have different optimizations for this:

  1. CSDN, rubbish

Image

  1. cnblog, perfect

Image

  1. MdBook,rubbish

Image

  1. VuePress/Vitepress (shiki),There is a deficiency for the code block type

Image

First, compare the second and the fourth points. Then I tried to track the differences between them. What kind of code affected the copied and pasted content? Is there additional js control or is it purely determined by the dom structure? After debugging, it was found to be the latter. Just add a class of language-xxxx to the code and it will be fine.

As long as a class is added, the annotation of the code block type during copying can be completed.

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions