himalaya icon indicating copy to clipboard operation
himalaya copied to clipboard

Code in script block may break output

Open 07akioni opened this issue 4 years ago • 3 comments

Input:

<div>
  <script>
    console.log('</')
  </script>
</div>

Output:

[
  {
    "type": "element",
    "tagName": "div",
    "attributes": [],
    "children": [
      {
        "type": "text",
        "content": "\n  "
      },
      {
        "type": "element",
        "tagName": "script",
        "attributes": [],
        "children": [
          {
            "type": "text",
            "content": "\n    console.log('"
          },
          {
            "type": "attribute",
            "content": "<"
          },
          {
            "type": "tag-end"
          },
          {
            "type": "text",
            "content": "cript>\n"
          }
        ]
      }
    ]
  }
]

07akioni avatar May 11 '21 17:05 07akioni

Hmm; this ought to be fixed, it should work as you expect and has some special handling already: https://github.com/andrejewski/himalaya/blob/master/src/tags.js#L5

@07akioni are you interested in making the fix and adding tests to prevent it from regressing? I'll review any PRs 😄

andrejewski avatar May 20 '21 23:05 andrejewski

Hmm; this ought to be fixed, it should work as you expect and has some special handling already: https://github.com/andrejewski/himalaya/blob/master/src/tags.js#L5

@07akioni are you interested in making the fix and adding tests to prevent it from regressing? I'll review any PRs 😄

I may have a try later. In this period I am a little busy😂

07akioni avatar May 30 '21 16:05 07akioni

Hi,

I'm also seeing template tags getting parsed (although in my case, it's cool).

input:

<select style="width:200px;height:20px;font-size:11px;" v-model="content.dataRef">
       <template v-for="src in dataRefs">
              <option :value="src">{{ src }}</option>
       </template>
 </select>

output:

[
  {
    "type": "element",
    "tagName": "select",
    "attributes": [
      {
        "key": "style",
        "value": "width:200px;height:20px;font-size:11px;"
      },
      {
        "key": "v-model",
        "value": "content.dataRef"
      }
    ],
    "children": [
      {
        "type": "element",
        "tagName": "template",
        "attributes": [
          {
            "key": "v-for",
            "value": "src in dataRefs"
          }
        ],
        "children": [
          {
            "type": "text",
            "content": "<option :value=\"src\">{{ src }}</option>"
          }
        ]
      }
    ]
  }
]

In the 'parser.js' file I didn't really see where the childlessTags get a look, but line 121 might be a fit with another || arrayIncludes(childless...).

If I knew how to use Github I'd test this theory out and do PR, ... but check the name (Noob). Thanks again for this work!!

Noobiest9 avatar May 26 '22 03:05 Noobiest9