Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to preserve HTML comments #25

Open
3 of 10 tasks
EvitanRelta opened this issue Dec 21, 2022 · 0 comments
Open
3 of 10 tasks

Option to preserve HTML comments #25

EvitanRelta opened this issue Dec 21, 2022 · 0 comments
Labels
feature New feature

Comments

@EvitanRelta
Copy link
Owner

EvitanRelta commented Dec 21, 2022

Basic idea

Given these HTML:

<!-- BELOW IS A HEADING -->
<h1>Heading</h1>

<!-- BELOW IS A PARAGRAPH -->
<p>Paragraph</p>
<h1>Heading</h1>
<!-- ABOVE IS A HEADING -->

<p>Paragraph</p>
<!-- ABOVE IS A PARAGRAPH -->
<h1>Heading</h1>

<!-- INBETWEEN -->

<p>Paragraph</p>

The conversion will attempt to place the comment close to it's original siblings, like:

<!-- THIS IS A HEADING -->
# Heading

<!-- THIS IS A PARAGRAPH -->
Paragraph
# Heading
<!-- ABOVE IS A HEADING -->

Paragraph
<!-- ABOVE IS A PARAGRAPH -->
# Heading

<!-- INBETWEEN -->

Paragraph

No blank-lines on both sides

If the comment in the HTML has no blank-lines between it and BOTH its sibling elements, like:

<h1>Heading</h1>
<!-- NO BLANK LINES ON BOTH SIDES -->
<p>Paragraph</p>

then a blank-line will be added on both sides:

# Heading

<!-- NO BLANK LINES ON BOTH SIDES -->

Paragraph

Multiple blank-lines

In cases where theres more than 1 blank-line between the comment and its sibling elements:

<h1>Heading</h1>



<!-- 3 BLANKS ABOVE, 2 BLANKS BELOW -->


<p>Paragraph</p>

Then the blank-lines are preserved:

# Heading



<!-- 3 BLANKS ABOVE, 2 BLANKS BELOW -->


Paragraph

Comments inside elements

Heading

<h1>
  <!-- COMMENT BEFORE -->
  Heading
  <!-- COMMENT AFTER -->
</h1>
# <!-- COMMENT BEFORE -->Heading<!-- COMMENT AFTER -->

Paragraph

<p>
  <!-- COMMENT BEFORE -->
  Paragraph
  <!-- COMMENT AFTER -->
</p>
<!-- COMMENT BEFORE -->
Paragraph
<!-- COMMENT AFTER -->

List

<ul>
  <!-- OUTSIDE LIST-ITEM (BEFORE) -->
  <li>Item 1</li>
  <li>
    <!-- INSIDE LIST ITEM (BEFORE) -->
    Item 2
    <!-- INSIDE LIST ITEM (AFTER) -->
  </li>
  <li>Item 3</li>
  <!-- OUTSIDE LIST-ITEM (AFTER) -->
</ul>
<!-- OUTSIDE LIST-ITEM (BEFORE) -->
- Item 1
- <!-- INSIDE LIST ITEM (BEFORE) -->
  Item 2
  <!-- INSIDE LIST ITEM (AFTER) -->
- Item 3
<!-- OUTSIDE LIST-ITEM (AFTER) -->

Cases to add to issue's description:

  • Heading
  • Paragraph
  • Tight-list
  • Loose-list
  • Blockquote
  • Codeblock
  • Table
  • Hyperlink (ie. <a>)
  • Text-formattings
    (ie. bold, italics, code, strikethrough, sub/superscript, underline)
  • Comments inside tags
    (eg. <h1 <!-- COMMENT--> >)
@EvitanRelta EvitanRelta added the feature New feature label Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

No branches or pull requests

1 participant