使用 Grunt 检索 html 正文的内容

Retrieving the contents of the html body using Grunt

本文关键字:正文 html Grunt 检索 使用      更新时间:2023-09-26

是否有一个咕噜咕噜的任务可以抓取 html 正文的内容并将其放在一个单独的文件中?

<html>
    <body>
        <h1>Grab this</h1>
        <h2>And this</h2>
    </body>
</html>

您可以使用 Grunt 的复制文件部分来选择正文。

文档在这里。https://www.npmjs.com/package/grunt-copy-part-of-file

例如

grunt.initConfig({
    copy_part_of_file: {
        simple_replace_scripts: {
            options: {
                sourceFileStartPattern: '<body>',
                sourceFileEndPattern: '</body>',
                destinationFileStartPattern: '',
                destinationFileEndPattern: ''
            },
            files: {
                'test/fixtures/simple-destination.html': ['test/fixtures/simple-source.html']
            }
        }
    },
})