posthtml / posthtml-extend

Template extending (Jade-like)
MIT License
46 stars 9 forks source link

[posthtml-extend] Unexpected block "title" #34

Closed Asuka109 closed 3 years ago

Asuka109 commented 3 years ago

The block tag embedded in the title tag doesn't work properly, which seems to be unique to the new version.

index.html

<extends src="base.html">
  <block name="title">Document</block>
  <block name="body">
    <p>Welcome~</p>
  </block>
</extends>

base.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>
    <block name="title">Document</block>
  </title>
</head>
<body>
  <div id="app">
    <block name="body"></block>
  </div>
</body>
</html>

And then will get:

Error: [posthtml-extend] Unexpected block "title"
    at getError (E:\repositories\wecall-qyh\node_modules\posthtml-extend\lib\index.js:1:3740)
    at mergeExtendsAndLayout (E:\repositories\wecall-qyh\node_modules\posthtml-extend\lib\index.js:1:2705)
    at E:\repositories\wecall-qyh\node_modules\posthtml-extend\lib\index.js:1:1743
    at E:\repositories\wecall-qyh\node_modules\posthtml\lib\api.js:91:45
    at traverse (E:\repositories\wecall-qyh\node_modules\posthtml\lib\api.js:105:26)
    at Array.match (E:\repositories\wecall-qyh\node_modules\posthtml\lib\api.js:90:7)
    at handleExtendsNodes (E:\repositories\wecall-qyh\node_modules\posthtml-extend\lib\index.js:1:1262)
    at E:\repositories\wecall-qyh\node_modules\posthtml-extend\lib\index.js:1:901
    at err (E:\repositories\wecall-qyh\node_modules\posthtml\lib\index.js:219:34)
    at tryCatch (E:\repositories\wecall-qyh\node_modules\posthtml\lib\index.js:300:12)

But this will works right:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <block name="title">123123</block>
</head>
<body>
  <div id="app">
    <block name="body"></block>
  </div>
</body>
</html>
Scrum commented 3 years ago

@Asuka109 https://github.com/posthtml/posthtml-parser/issues/53#issuecomment-734352562