Re: [Videlibri-xidel] Extract css into separate files?
Client for public libraries
Brought to you by:
benibela
|
From: Peng Yu <pen...@gm...> - 2023-05-07 14:06:37
|
On 5/6/23, Peng Yu <pen...@gm...> wrote:
> Hi,
>
> $ cat 1.html
> <!DOCTYPE html>
> <html>
> <head>
> <style>
> body {background-color: powderblue;}
> </style>
> <style>
> h1 {color: blue;}
> </style>
> <style>
> p {color: red;}
> </style>
> </head>
> <body>
>
> <h1>This is a heading</h1>
> <p>This is a paragraph.</p>
>
> </body>
> </html>
>
> Suppose that I have a html file css styles embedded. I want to extract
> CSS into separate files.
>
> The end result should be an HTML file that looks exactly the same as
> in the browser.
>
> I can use the following bash commands to extract CSS files. Is this
> the best way to do so? (I'd think a one-path method might be better.
> But it is not clear how to dump output to multiple files in xidel.)
>
> n=$(xidel -s -e 'count(//style)' 1.html)
> mkdir -p css
> for((i=1;i<=n;++i)); do
> xidel -s -e '//style[$i]' 1.html > css/1.css
Here is a typo. The code should have been the following.
xidel -s -e "//style[$i]" "$i.html" > css/"$i.css"
> done
>
> I then try to replace <css> with <link>.
> xidel --input-format html --output-format html --in-place -s -e
> 'x:replace-nodes(//style[1], <link rel="stylesheet"
> href="css/1.css">)' 1.html
>
> But I got an error like this.
> x:replace-nodes(//style[1], <link rel="stylesheet" href="css/1.css">)
> ^^^^^^^^^^^^^^^^^^
> error occurs around here
>
> How to perform the replacement correctly? Thanks.
> --
> Regards,
> Peng
>
--
Regards,
Peng
|