Skip to content

Automatically remove blank lines in HTML blocks #7921

Closed
@Zuoqiu-Yingyi

Description

@Zuoqiu-Yingyi
Contributor

HTML 块存在空行时造成运行时异常

Is there an existing issue for this?

  • I have searched the existing issues

Can the issue be reproduced with the default theme (daylight/midnight)?

  • I was able to reproduce the issue with the default theme

Could the issue be due to extensions?

  • I've ruled out the possibility that the extension is causing the problem.

Describe the problem

HTML 块存在空行时提示 形成了多个 HTML 块,为防止数据丢失请使用 <div> 标签包裹并去掉空行, 然后点击编辑按钮进行编辑时出现运行时异常
When there are empty lines in the HTML block, prompts Multiple HTML blocks are formed. To prevent data loss, please use <div> tags to wrap and remove blank lines, and then click the Edit button to edit a runtime exception when editing

Expected result

HTML 块在保存时自动移除空行
HTML blocks automatically remove empty lines when saved

Screenshot or screen recording presentation

No response

Version environment

- Version: 2.8.4-dev1
- Operating System: 
- Browser (if used):

Log file

E 2023/04/07 21:39:36 transaction.go:861: get node [20230407213820-etg2jy8] in tree [20230407212329-u4jaait] failed

More information

No response

Activity

changed the title [-]HTML 块存在空行时造成运行时异常 | HTML block with blank line parsing errors cause run-time exceptions[/-] [+]HTML block with blank line parsing errors cause run-time exceptions[/+] on Apr 7, 2023
88250

88250 commented on Apr 9, 2023

@88250
Member

麻烦给出原始的 HTML 块内容。

Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Apr 9, 2023

@Zuoqiu-Yingyi
ContributorAuthor

麻烦给出原始的 HTML 块内容。

<div>
    <button id="button">
        更新用户指南
    </button>
    <script type="module">
        {
            /* 自定义 ID */
            const CUSTOM_ID = "E4555D40-2E2B-4C40-9598-AE05B77CEB9F";
            /**
             * HTML 块中的脚本获取当前块相关信息
             * @param {string} customID 内部定义的 ID
             * @returns {string} id 当前 HTML 块 ID
             * @returns {HTMLElement} block 当前 HTML 块
             * @returns {HTMLElement} shadowRoot 当前 HTML 块 shadowRoot
             */
            function This(customID) {
                let protyle = document.querySelector(`protyle-html[data-content*="${customID}"]`);
                if (protyle) {
                    let block = protyle.parentElement.parentElement;
                    return {
                        id: block.dataset.nodeId,
                        block: block,
                        shadowRoot: protyle.shadowRoot,
                    };
                } else return null;
            }

            const NOTEBOOKS_ID_LIST = [
                "20210808180117-czj9bvb", // 简体中文用户指南
                "20211226090932-5lcq56f", // 繁体中文用户指南
                "20210808180117-6v0mkxr", // 英文用户指南
            ]; // 用户指南笔记本 ID 列表
            const URL = "/api/notebook/openNotebook"; // 重新打开笔记本的 API
            const THIS = This(CUSTOM_ID); // 获取当前 HTML 块相关信息
            const BUTTON = THIS.shadowRoot.getElementById("button"); // 获取按钮元素

            async function reOpenUserGuide() {
                NOTEBOOKS_ID_LIST.forEach(notebook_id => {
                    fetch(URL, {
                        body: JSON.stringify({
                            notebook: notebook_id,
                        }),
                        method: 'POST',
                    });
                });
            }

            BUTTON.addEventListener("click", reOpenUserGuide);
        }
    </script>
</div>
changed the title [-]HTML block with blank line parsing errors cause run-time exceptions[/-] [+]Automatically remove blank lines in HTML blocks[/+] on Apr 11, 2023
added this to the 2.8.5 milestone on Apr 11, 2023
added a commit that references this issue on Apr 12, 2023
added a commit that references this issue on Apr 14, 2023
50f7e97
added a commit that references this issue on Apr 14, 2023
28f3920
Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Apr 15, 2023

@Zuoqiu-Yingyi
ContributorAuthor

貌似还是没完全修好

2.8.5-dev2 中 HTML 块内插入如下内容

<div>
    123
</div>

关闭输入框后再打开输入框, 结尾会多出一个 标签, 如下所示

<div>
    123
</div>
</div>
Zuoqiu-Yingyi

Zuoqiu-Yingyi commented on Apr 15, 2023

@Zuoqiu-Yingyi
ContributorAuthor

应该定位到问题了, 稍后我提交一个 PR

added 3 commits that reference this issue on Apr 15, 2023
370ed29
2c20385
94f1bcf
added a commit that references this issue on Apr 17, 2023
8976709
removed this from the 2.8.5 milestone on Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @88250@Vanessa219@Zuoqiu-Yingyi

      Issue actions

        Automatically remove blank lines in HTML blocks · Issue #7921 · siyuan-note/siyuan