Using xmlstarlet non XML compliant documents (XHTML) - linux

I have non XML compliant documents (XHTML pages) with improperly closed tags,img, br, hr.
I need close image, hr, and br tags properly, with '/>'
I tried xmlstarlet, it does the job, but alters XML declaration header.
So I have original code as follows:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<title> </title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
if I run command xmlstarlet fo --recover --html file.xhtml,
the output is incorrect, have 2 declaration lines:
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE html>
<?xml version="1.0" encoding="UTF-8" standalone="no"??>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<title> </title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
if I run xmlstarlet fo --omit-decl --recover --html file.xhtml,
the output is also incorrect, as declaration need be the first line:
<!DOCTYPE html>
<?xml version="1.0" encoding="UTF-8" standalone="no"??>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<title> </title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
So I need to do post-processing, swap the first and second lines. What bash command can help here? Please specify command syntax for bath processing files and editing in place.
P.S. why xmlstarlet put 2 question mark chars at the end of declaration? ("no"??>)

I suggest to append | sed -n '1{h;d};2{p;g};p'.

This might work for you (GNU sed):
sed -zE 's/(.*)\n(.*)/\2\n\1/m' file
Slurp the file into memory and swap the contents of line 1 and 2.
N.B. The m flag allows .* to refer to lines contents.

Related

Color not showing in output text when sent via email

I have a test script where I am trying to redirect the result in colored text. I have achieved this using linux color codes. It works when I execute the script from command line but when I try to send the output of the script as attachment via mailx it is not showing me the color instead the attachment is appearing with color code# along with the text.
Can anyone help and suggest on this please?
Eg:
In mail attachment, I'm getting the result as below but in server if the script is executed, the below line is printed (echo'd) in the command prompt properly in RED color.
[1;31m This is red text [0m
Code Snippet:
#FONT Color
RED='\033[0;31m'
NC='\033[0m'
echo -e "${RED}This is RED Text${NC}" > /tmp/test.txt
echo "Colored text check" | mailx -s "color_test" -a /tmp/test.txt abc#xyz.com
<html lang="en">
<!--
Purple: #a20067
Dark Blue: #005eb8
-->
<head>
<meta charset="utf-8">
</head>
<body>
<style>
p { margin:0; padding:0; }
.h { border-width:1px;border-style:solid;background-color:#005eb8;color:#ffffff;font-weight:bold;text-align:left;padding:8px; }
.v { border-width:1px;border-style:solid;background-color:#c6c7c8;color:black;font-weight:bold;text-align:left;padding:8px; }
</style>
There you can have an example of a e-mail sent from a terminal with colour, there I just used dark blue, even though I specified purple. It was used later in that e-mail.

AsciiDoctor: How can I add custom xmlns'

How can I add a custom xmlns in the output when I convert an asciidoc file with AsciiDoctor?
I'd like to add xmlns:xi="http://www.w3.org/2001/XInclude" in the top book tag.
The current implementation seems to generate:
<?xml version="1.0" encoding="UTF-8"?>
<?asciidoc-toc?>
<?asciidoc-numbered?>
<book xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<info>
<title>title</title>
</info>
</book>
from this:
= title
:lang: en
When I run:
$ asciidoctor -b docbook5 -d book -o out.xml source.txt
There is a built-in attribute xmlns, but it seems to be for docbook 4.5.
The reason I want to use XInclude is to include some xml files from Docinfo files and Passthrough Blocks
With a bit of research inside the asciidoctor code it quickly became clear that the part you'd like to modify is fairly static.
See asciidoctor/converter/docbook5.rb Line 44 for more info.
The best approach is to create a postprocessor extension which modifies the output. The example below is just to show a possible implementation.
Create a file with the following content and call it docbook_postprocessor.rb.
class Docbook5XiPostprocessor < Asciidoctor::Extensions::Postprocessor
def process document, output
if document.basebackend? 'docbook'
input_regex = %r{^(<.*xmlns:xl="http://www.w3.org/1999/xlink") (version="5.0".*>)}
replacement = %(\\1 xmlns:xi="http://www.w3.org/2001/XInclude" \\2)
output = output.sub(input_regex, replacement)
end
output
end
end
Asciidoctor::Extensions.register do
postprocessor Docbook5XiPostprocessor
end
Note: The above extension is for the sake of brevity placed in the same directory as the asciidoctor source file called source.adoc.
The run the asciidoctor command with the -r ./docbook_postprocessor.rb parameters.
$ asciidoctor -r ./docbook_postprocessor.rb -b docbook5 -d book -o - source.adoc
<?xml version="1.0" encoding="UTF-8"?>
<?asciidoc-toc?>
<?asciidoc-numbered?>
<book
xmlns="http://docbook.org/ns/docbook"
xmlns:xl="http://www.w3.org/1999/xlink"
xmlns:xi="http://www.w3.org/2001/XInclude"
version="5.0"
xml:lang="en">
<info>
<title>test</title>
<date>2020-12-19</date>
</info>
</book>
* Above output has been slightly reformatted to eliminate the scrollbar
Creating ruby gem with the above code for easier distribution is a task left to the reader.

WAMP not updating changes in my files

So I am a novice at Web development and I am trying to create a website and am using WAMP to test out my PHP code and such. The issue I'm running into is that when I change my file, and try to refresh my localhost page on my browser, it gives me a file not found error. When I close out the localhost page and reopen it, the page that I changed appears properly and is updated properly.
I was just wondering whether there is an issue with my WAMP or whether having to open a new localhost page is necessary every time a file is updated?
I would ensure the file path is correct, double check that you are dev-ing from the same folder that you are viewing in localhost. Also what worked for me is doing a browser cache refresh which is different from a simple refresh. http://refreshyourcache.com/en/cache/
Windows: ctrl + F5
Mac/Apple: Apple + R or command + R
Linux: F5
<link rel="stylesheet" href="http://localhost/CI-social-media/css/registration_form.css?v=<?php echo time(); ?>">
<script language="javascript" src="http://localhost/CI-social-media/js/registration_form.js?v=<?php echo time(); ?>"></script>
<link rel="stylesheet" href="http://localhost/CI-social-media/css/registration_form.css?v=<?php echo time(); ?>">
<script language="javascript" src="http://localhost/CI-social-media/js/registration_form.js?v=<?php echo time(); ?>"></script>
use this & solved problem
just add ?v=<?php echo time(); ?> after href="('path/url') then after "
just add ?v=<?php echo time(); ?> after src="('path/url') then after "
<link rel="stylesheet" href="http://localhost/CI-social-media/css/registration_form.css?v=<?php echo time(); ?>">
<script language="javascript" src="http://localhost/CI-social-media/js/registration_form.js?v=<?php echo time(); ?>"></script>

wget fail to save audio files in a page

I am running this wget, able to save everything (css, html, images, relative path reference etc) from a webpage, except the audio (alert.mp3, alert.ogg)
Is it due to limitation of wget when come to getting this audio from this format?
<?php
exec("wget --no-parent --timestamping --convert-links --page-requisites -erobots=off http://webpage/index.html");
?>
<html>
<body>
bla bla bla
<audio autoplay="autoplay" preload=""><source src="alert.mp3" type="audio/mpeg"><source src="alert.ogg" type="audio/ogg"></audio>
</body>
</html>

how to get unicode in svg

this is the first line in my .svg image
<?xml version="1.0" encoding="UTF-8"?>
this is inside head part of .php file:
<meta charset="utf-8">
this is checked in Notepad++ - Encoding menu:
Encode in UTF-8 without BUM
or (I tried):
Encode in UTF-8
Still, my img does not display unicode character !?

Resources