How to configure VIM Ale to use the Tidy linter for HTML? - vim

I'm trying to configure the vim Ale plugin to use Tidy to lint HTML code.
I added to my .vimrc file:
let g:ale_linters = {
\ 'css': ['csslint'],
\ 'html': ['tidy'],
\ 'javascript': ['eslint'],
\ 'php': [''],
\ 'python': ['flake8'],
\}
I got the linters working for CSS, JavaScript, and Python, but not HTML.
:ALEInfo outputs:
Current Filetype: html
Available Linters: ['alex', 'fecs', 'htmlhint', 'proselint', 'stylelint', 'tidy', 'writegood']
Linter Aliases: 'writegood' -> ['write-good']
Enabled Linters: ['tidy']
. . . at the end of the information . . .
Command History: (executable check - success) tidy
It looks like the Tidy linter is available and configured, but I can't get it to work. The html files seem to have no linting at all.
I am able to run Tidy successfully in the terminal:
> tidy test.html
line 1 column 1 - Warning: missing <!DOCTYPE> declaration
line 1 column 1 - Warning: plain text isn't allowed in <head> elements
line 1 column 2 - Warning: discarding unexpected <html>
line 2 column 5 - Warning: <body> unexpected or duplicate quote mark
line 2 column 5 - Warning: discarding unexpected <body>
line 4 column 7 - Error: <bdy> is not recognized!
line 4 column 7 - Warning: discarding unexpected <bdy>
line 1 column 1 - Warning: inserting missing 'title' element
line 3 column 7 - Warning: trimming empty <p>
Info: Document content looks like HTML 3.2
8 warnings, 1 error were found!
How can I get Tidy to work with Ale in vim?

You also need to tell vim where to find the tidy executable, e.g., tidy on Linux, or tidy.exe on Windows.
In my case, I added this to my vimrc:
let g:ale_html_tidy_executable = "D://TidyHtml//tidy-5.6.0-vc14-64b//bin//tidy.exe"
In vim, to get Ale help for tidy: :h ale-html-tidy

Related

SED style Multi address in Python?

I have an app that parses multiple Cisco show tech files. These files contain the output of multiple router commands in a structured way, let me show you an snippet of a show tech output:
`show clock`
20:20:50.771 UTC Wed Sep 07 2022
Time source is NTP
`show callhome`
callhome disabled
Callhome Information:
<SNIPET>
`show module`
Mod Ports Module-Type Model Status
--- ----- ------------------------------------- --------------------- ---------
1 52 16x10G + 32x10/25G + 4x100G Module N9K-X96136YC-R ok
2 52 16x10G + 32x10/25G + 4x100G Module N9K-X96136YC-R ok
3 52 16x10G + 32x10/25G + 4x100G Module N9K-X96136YC-R ok
4 52 16x10G + 32x10/25G + 4x100G Module N9K-X96136YC-R ok
21 0 Fabric Module N9K-C9504-FM-R ok
22 0 Fabric Module N9K-C9504-FM-R ok
23 0 Fabric Module N9K-C9504-FM-R ok
<SNIPET>
My app currently uses both SED and Python scripts to parse these files. I use SED to parse the show tech file looking for a specific command output, once I find it, I stop SED. This way I don't need to read all the file (these can get to be very big files). This is a snipet of my SED script:
sed -E -n '/`show running-config`|`show running`|`show running config`/{
p
:loop
n
p
/`show/q
b loop
}' $1/$file
As you can see I am using a multi address range in SED. My question specifically is, how can I achieve something similar in python? I have tried multiple combinations of flags: DOTALL and MULTILINE but I can't get the result I'm expecting, for example, I can get a match for the command I'm looking for, but python regex wont stop until the end of the file after the first match.
I am looking for something like this
sed -n '/`show clock`/,/`show/p'
I would like the regex match to stop parsing the file and print the results, immediately after seeing `show again , hope that makes sense and thank you all for reading me and for your help
You can use nested loops.
import re
def process_file(filename):
with open(filename) as f:
for line in f:
if re.search(r'`show running-config`|`show running`|`show running config`', line):
print(line)
for line1 in f:
print(line1)
if re.search(r'`show', line1):
return
The inner for loop will start from the next line after the one processed by the outer loop.
You can also do it with a single loop using a flag variable.
import re
def process_file(filename):
in_show = False
with open(filename) as f:
for line in f:
if re.search(r'`show running-config`|`show running`|`show running config`', line):
in_show = True
if in_show
print(line)
if re.search(r'`show', line1):
return

AutoHotKey: read of two underscore keys

One part of my AutoHotKey script should recognize if __ is typed.
Following the AutoHotKey documentation, I've tried:
~__::
tooltip,hi world
return
and got this error:
Line Text: ~__::
Error: Invalid hotkey.
this shows no errors, but works only for one underscore:
~_::
tooltip,hi world
return
this shows no errors, but it just clears the __:
:*:__::
tooltip,hi world
return
this shows error Error: Invalid hotkey.:
~:*:__::
tooltip,hi world
return
this shows no errors, but does nothing (Doku: Executehotstring) :
:X:~__::
tooltip,hi world
return
Here are 4 potential solutions. I have left one working, comment out/uncomment hotkey labels by adding/removing leading semicolons as appropriate.
The 2 blocks of code are functionally equivalent, and for the 2 alternatives, within each block, b0 prevents automatic backspacing, i.e. the underscores that you typed are not deleted.
;:*?:__:: ;deletes the underscores
:b0*?:__:: ;does not delete the underscores
SoundBeep
return
;note: the X option requires AHK v1.1.28+
;:X*?:__::SoundBeep ;deletes the underscores
;:Xb0*?:__::SoundBeep ;does not delete the underscores
This AutoHotKey recognize if __ is typed:
countUnderscore :=0
~_::
countUnderscore++
if(countUnderscore == 2){
tooltip, %countUnderscore% = countUnderscore
countUnderscore := 0
}
return

Unable to trim the last line in the Unix file

I am trying to create and unix file with some text in it with the below command:
ssh.sendLine("echo '"+"{1:F01ZYIBGB20AXXX0000000000}{2:O5481710NDEASES0XXXX12345678901511041511180930N}\n{4:\n:16R:GENL\n:20C::SEME//"+$TradeRef+"\n:23G:INST\n:16R:LINK\n:20C::RELA//"+$TradeRef+"\n:16S:LINK\n:16R:STAT\n:25D::MTCH//MACH\n:16S:STAT\n:16S:GENL\n:16R:SETTRAN\n:35B:ISIN DE0005933931\niShares Core DAX UCITS ETF DE\n:36B::SETT//UNIT/10,\n:97A::SAFE//8696\n:22F::SETR//TRAD\n:98A::SETT//20151118\n:98A::TRAD//20151118\n:16S:SETTRAN\n-}'"+">M548File.txt");
NOw this command is createing the file M548File.txt.
When id a cat this is what i get :
{1:F01ZYIBGB20AXXX0000000000}{2:O5481710NDEASES0XXXX12345678901511041511180930N}
{4:
:16R:GENL
:20C::SEME//11111111111111111111
:23G:INST
:16R:LINK
:20C::RELA//11111111111111111111
:16S:LINK
:16R:STAT
:25D::MTCH//MACH
:16S:STAT
:16S:GENL
:16R:SETTRAN
:35B:ISIN DE0005933931
iShares Core DAX UCITS ETF DE
:36B::SETT//UNIT/10,
:97A::SAFE//8696
:22F::SETR//TRAD
:98A::SETT//20151118
:98A::TRAD//20151118
:16S:SETTRAN
-}
However when i try to open the same file in notepad i get one extraline at the last which is basically an empty line making it a total of -- 23 lines as compared to 22 in cat.
I tried the Sed commands but it just not working
Any idea how to overcome this to get 22 lines in notepad(same as cat)?

Why read.clipboard is not working in R

Why is read.clipboard() not working on my system?
> library(psych)
> read.table(text=read.clipboard(), sep="\t", header=T, stringsAsFactors=F, strip.white=T)
Error in textConnection(text, encoding = "UTF-8") :
invalid 'text' argument
In addition: Warning message:
In read.table(file("clipboard"), header = TRUE, ...) :
incomplete final line found by readTableHeader on 'clipboard'
> read.table(text=readClipboard(), sep="\t", header=T, stringsAsFactors=F, strip.white=T)
Error in textConnection(text, encoding = "UTF-8") :
could not find function "readClipboard"
The version information:
> packageVersion('psych')
[1] ‘1.4.8.11’
> R.version
_
platform i486-pc-linux-gnu
arch i486
os linux-gnu
system i486, linux-gnu
status
major 3
minor 1.1
year 2014
month 07
day 10
svn rev 66115
language R
version.string R version 3.1.1 (2014-07-10)
nickname Sock it to Me
>
EDIT:
As suggested by #RichardScriven, I used following:
read.table('clipboard', sep="\t", header=T)
If I copy some cells in a spreadsheet and try above command, it does not work. Following is the error:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : clipboard cannot be opened or contains no text
But if I paste first to a text editor, and copy it again from there, then the above command works well.
How can I directly use the data after copying from a spreadsheet?
Following command also shows same problem, works when copied from text editor but not when copied from spreadsheet. I produces same error.
> read.clipboard(sep="\t", header=T)
Error in open.connection(file, "rt") : cannot open the connection
In addition: Warning message:
In open.connection(file, "rt") :
clipboard cannot be opened or contains no text
read.clipboard(sep="\t",header = T)
The above code should work. Also please note that you need to copy [from excel / libreoffice etc] , go to R script and run the command in R. If you perform any other commands in between, this might not work. Hope this helps.

Pdflatex error when using {-" ... "-} inline TeX comments in lhs2TeX

I have the following code block in my .lhs file which uses inline TeX comments:
\begin{code}
main = print 0
{-"$\langle$Link$\rangle$"-}
\end{code}
However, after compiling with lhs2TeX, I get the following errors when compiling the generated .tex file:
! Missing $ inserted.
<inserted text>
$
l.269 \end{hscode}
\resethooks
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
! LaTeX Error: Bad math environment delimiter.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.269 \end{hscode}
\resethooks
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.
! Missing $ inserted.
<inserted text>
$
l.269 \end{hscode}
\resethooks
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
! LaTeX Error: Bad math environment delimiter.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.269 \end{hscode}
\resethooks
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.
! Missing $ inserted.
<inserted text>
$
l.269 \end{hscode}
\resethooks
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
! LaTeX Error: Bad math environment delimiter.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.269 \end{hscode}
\resethooks
Your command was ignored.
When I remove the " marks in the inline comment, the error disappears. Anyone know what's wrong?
P.S Here's the .tex file that lhs2TeX generates:
\documentclass{article}%% ODER: format == = "\mathrel{==}"
%% ODER: format /= = "\neq "
%
%
\makeatletter
\#ifundefined{lhs2tex.lhs2tex.sty.read}%
{\#namedef{lhs2tex.lhs2tex.sty.read}{}%
\newcommand\SkipToFmtEnd{}%
\newcommand\EndFmtInput{}%
\long\def\SkipToFmtEnd#1\EndFmtInput{}%
}\SkipToFmtEnd
\newcommand\ReadOnlyOnce[1]{\#ifundefined{#1}{\#namedef{#1}{}}\SkipToFmtEnd}
\usepackage{amstext}
\usepackage{amssymb}
\usepackage{stmaryrd}
\DeclareFontFamily{OT1}{cmtex}{}
\DeclareFontShape{OT1}{cmtex}{m}{n}
{<5><6><7><8>cmtex8
<9>cmtex9
<10><10.95><12><14.4><17.28><20.74><24.88>cmtex10}{}
\DeclareFontShape{OT1}{cmtex}{m}{it}
{<-> ssub * cmtt/m/it}{}
\newcommand{\texfamily}{\fontfamily{cmtex}\selectfont}
\DeclareFontShape{OT1}{cmtt}{bx}{n}
{<5><6><7><8>cmtt8
<9>cmbtt9
<10><10.95><12><14.4><17.28><20.74><24.88>cmbtt10}{}
\DeclareFontShape{OT1}{cmtex}{bx}{n}
{<-> ssub * cmtt/bx/n}{}
\newcommand{\tex}[1]{\text{\texfamily#1}} % NEU
\newcommand{\Sp}{\hskip.33334em\relax}
\newcommand{\Conid}[1]{\mathit{#1}}
\newcommand{\Varid}[1]{\mathit{#1}}
\newcommand{\anonymous}{\kern0.06em \vbox{\hrule\#width.5em}}
\newcommand{\plus}{\mathbin{+\!\!\!+}}
\newcommand{\bind}{\mathbin{>\!\!\!>\mkern-6.7mu=}}
\newcommand{\rbind}{\mathbin{=\mkern-6.7mu<\!\!\!<}}% suggested by Neil Mitchell
\newcommand{\sequ}{\mathbin{>\!\!\!>}}
\renewcommand{\leq}{\leqslant}
\renewcommand{\geq}{\geqslant}
\usepackage{polytable}
%mathindent has to be defined
\#ifundefined{mathindent}%
{\newdimen\mathindent\mathindent\leftmargini}%
{}%
\def\resethooks{%
\global\let\SaveRestoreHook\empty
\global\let\ColumnHook\empty}
\newcommand*{\savecolumns}[1][default]%
{\g#addto#macro\SaveRestoreHook{\savecolumns[#1]}}
\newcommand*{\restorecolumns}[1][default]%
{\g#addto#macro\SaveRestoreHook{\restorecolumns[#1]}}
\newcommand*{\aligncolumn}[2]%
{\g#addto#macro\ColumnHook{\column{#1}{#2}}}
\resethooks
\newcommand{\onelinecommentchars}{\quad-{}- }
\newcommand{\commentbeginchars}{\enskip\{-}
\newcommand{\commentendchars}{-\}\enskip}
\newcommand{\visiblecomments}{%
\let\onelinecomment=\onelinecommentchars
\let\commentbegin=\commentbeginchars
\let\commentend=\commentendchars}
\newcommand{\invisiblecomments}{%
\let\onelinecomment=\empty
\let\commentbegin=\empty
\let\commentend=\empty}
\visiblecomments
\newlength{\blanklineskip}
\setlength{\blanklineskip}{0.66084ex}
\newcommand{\hsindent}[1]{\quad}% default is fixed indentation
\let\hspre\empty
\let\hspost\empty
\newcommand{\NB}{\textbf{NB}}
\newcommand{\Todo}[1]{$\langle$\textbf{To do:}~#1$\rangle$}
\EndFmtInput
\makeatother
%
%
%
%
%
%
% This package provides two environments suitable to take the place
% of hscode, called "plainhscode" and "arrayhscode".
%
% The plain environment surrounds each code block by vertical space,
% and it uses \abovedisplayskip and \belowdisplayskip to get spacing
% similar to formulas. Note that if these dimensions are changed,
% the spacing around displayed math formulas changes as well.
% All code is indented using \leftskip.
%
% Changed 19.08.2004 to reflect changes in colorcode. Should work with
% CodeGroup.sty.
%
\ReadOnlyOnce{polycode.fmt}%
\makeatletter
\newcommand{\hsnewpar}[1]%
{{\parskip=0pt\parindent=0pt\par\vskip #1\noindent}}
% can be used, for instance, to redefine the code size, by setting the
% command to \small or something alike
\newcommand{\hscodestyle}{}
% The command \sethscode can be used to switch the code formatting
% behaviour by mapping the hscode environment in the subst directive
% to a new LaTeX environment.
\newcommand{\sethscode}[1]%
{\expandafter\let\expandafter\hscode\csname #1\endcsname
\expandafter\let\expandafter\endhscode\csname end#1\endcsname}
% "compatibility" mode restores the non-polycode.fmt layout.
\newenvironment{compathscode}%
{\par\noindent
\advance\leftskip\mathindent
\hscodestyle
\let\\=\#normalcr
\let\hspre\(\let\hspost\)%
\pboxed}%
{\endpboxed\)%
\par\noindent
\ignorespacesafterend}
\newcommand{\compaths}{\sethscode{compathscode}}
% "plain" mode is the proposed default.
% It should now work with \centering.
% This required some changes. The old version
% is still available for reference as oldplainhscode.
\newenvironment{plainhscode}%
{\hsnewpar\abovedisplayskip
\advance\leftskip\mathindent
\hscodestyle
\let\hspre\(\let\hspost\)%
\pboxed}%
{\endpboxed%
\hsnewpar\belowdisplayskip
\ignorespacesafterend}
\newenvironment{oldplainhscode}%
{\hsnewpar\abovedisplayskip
\advance\leftskip\mathindent
\hscodestyle
\let\\=\#normalcr
\(\pboxed}%
{\endpboxed\)%
\hsnewpar\belowdisplayskip
\ignorespacesafterend}
% Here, we make plainhscode the default environment.
\newcommand{\plainhs}{\sethscode{plainhscode}}
\newcommand{\oldplainhs}{\sethscode{oldplainhscode}}
\plainhs
% The arrayhscode is like plain, but makes use of polytable's
% parray environment which disallows page breaks in code blocks.
\newenvironment{arrayhscode}%
{\hsnewpar\abovedisplayskip
\advance\leftskip\mathindent
\hscodestyle
\let\\=\#normalcr
\(\parray}%
{\endparray\)%
\hsnewpar\belowdisplayskip
\ignorespacesafterend}
\newcommand{\arrayhs}{\sethscode{arrayhscode}}
% The mathhscode environment also makes use of polytable's parray
% environment. It is supposed to be used only inside math mode
% (I used it to typeset the type rules in my thesis).
\newenvironment{mathhscode}%
{\parray}{\endparray}
\newcommand{\mathhs}{\sethscode{mathhscode}}
% texths is similar to mathhs, but works in text mode.
\newenvironment{texthscode}%
{\(\parray}{\endparray\)}
\newcommand{\texths}{\sethscode{texthscode}}
% The framed environment places code in a framed box.
\def\codeframewidth{\arrayrulewidth}
\RequirePackage{calc}
\newenvironment{framedhscode}%
{\parskip=\abovedisplayskip\par\noindent
\hscodestyle
\arrayrulewidth=\codeframewidth
\tabular{#{}|p{\linewidth-2\arraycolsep-2\arrayrulewidth-2pt}|#{}}%
\hline\framedhslinecorrect\\{-1.5ex}%
\let\endoflinesave=\\
\let\\=\#normalcr
\(\pboxed}%
{\endpboxed\)%
\framedhslinecorrect\endoflinesave{.5ex}\hline
\endtabular
\parskip=\belowdisplayskip\par\noindent
\ignorespacesafterend}
\newcommand{\framedhslinecorrect}[2]%
{#1[#2]}
\newcommand{\framedhs}{\sethscode{framedhscode}}
% The inlinehscode environment is an experimental environment
% that can be used to typeset displayed code inline.
\newenvironment{inlinehscode}%
{\(\def\column##1##2{}%
\let\>\undefined\let\<\undefined\let\\\undefined
\newcommand\>[1][]{}\newcommand\<[1][]{}\newcommand\\[1][]{}%
\def\fromto##1##2##3{##3}%
\def\nextline{}}{\) }%
\newcommand{\inlinehs}{\sethscode{inlinehscode}}
% The joincode environment is a separate environment that
% can be used to surround and thereby connect multiple code
% blocks.
\newenvironment{joincode}%
{\let\orighscode=\hscode
\let\origendhscode=\endhscode
\def\endhscode{\def\hscode{\endgroup\def\#currenvir{hscode}\\}\begingroup}
%\let\SaveRestoreHook=\empty
%\let\ColumnHook=\empty
%\let\resethooks=\empty
\orighscode\def\hscode{\endgroup\def\#currenvir{hscode}}}%
{\origendhscode
\global\let\hscode=\orighscode
\global\let\endhscode=\origendhscode}%
\makeatother
\EndFmtInput
%
\begin{document}\section{}Precis 0
\newline{}\subsubsection*{\texttt{test0.tweave:}}\begin{hscode}\SaveRestoreHook
\column{B}{#{}>{\hspre}l<{\hspost}#{}}%
\column{E}{#{}>{\hspre}l<{\hspost}#{}}%
\>[B]{}\Varid{main}\mathrel{=}\Varid{print}\;\mathrm{0}{}\<[E]%
\\
\>[B]{}$\langle$Link$\rangle${}\<[E]%
\ColumnHook
\end{hscode}\resethooks
\section{}Precis 1
\newline{}\subsubsection*{\texttt{test0.tweave:}}\begin{hscode}\SaveRestoreHook
\column{B}{#{}>{\hspre}l<{\hspost}#{}}%
\column{E}{#{}>{\hspre}l<{\hspost}#{}}%
\>[B]{}\Varid{accum}\;\Varid{i}\mathrel{=}\Varid{id}{}\<[E]%
\ColumnHook
\end{hscode}\resethooks
\end{document}
The {-" ... "-} construct is quite low-level. It drops you in the environment TeX currently is in, which happens to be math mode already. So the solution to your problem is simple. Write the code to be inserted as if you are in math mode.
A different option is to use a normal comment, but make the comment characters invisible using \invisiblecomments. Normal comments are typeset as text by lhs2TeX.
The following complete lhs2TeX document demonstrates both options:
\documentclass{article}
%include polycode.fmt
\begin{document}
% Assume you are in math mode already:
\begin{code}
main = print 0
{-"\langle\text{Link}\rangle"-}
\end{code}
% This works, too:
\invisiblecomments
\begin{code}
main = print 0
{- $\langle$Link$\rangle$ -}
\end{code}
\end{document}

Resources