How to achieve a simple <p> element with LyXHTML

Steve Litt slitt at troubleshooters.com
Sun Jul 10 22:11:13 UTC 2022


tush via lyx-users said on Sat, 09 Jul 2022 18:59:53 +0000

>I am trying to remove the html attributes assigned by LyXHTML to the
>Standard text inserted in the editor.
>
>LyX's default is to render Standard as
>
><div class="standard" id='magicparlabel-15'>This is text inserted in
>Standard</div>
>
>together with
>
>p.standard {
>
>text-align: left;
>
>}
>
>appearing in the header.
>
>What I want is to get the simple html code
>
><p>This is text inserted in Standard</p>
>In order to do that I am writing my Style in a layout file. What I
>have at the moment is the following:
>
>(I copied the first rows from stdclass.inc)
>
>Style Standard
>	Category              MainText
>	Margin                Static
>	LatexType             Paragraph
>	LatexName             dummy
>	ParIndent             MM
>	ParSkip               0.4
>	Align                 Block
>	AlignPossible         Block, Left, Right, Center
>	LabelType             No_Label
>
>HTMLAttr " "
>
>End
>
>After a lot of trial and error, using the last line I eliminated the
>"div class="standard"" from the p element but still LyX assigns to it
>an id="some number" which I want to eliminate too.
>
>Any idea about it would be very welcome.

Yeahhhhhh, this is one of the reasons I don't use LyX for ePub. Last
time I looked, LyX exports used the deprecated and now with HTML5
eliminated <a name="whatever"/> inside a div specially made to contain
one <p></p>. What could *possibly* go wrong?

If I had to eliminate these redundant <div></div> things, I'd do it
with a postprocessor that corrects LyX' complexifications. It's not
easy, but you can use Python with the "import xml.etree.ElementTree as
ET" library. You'd analyze every DOM element, and for every <div/>
whose only purpose is to encase one <p/>, get rid of the div after
reading metadata from that <div/> and any <a name=> silliness, applying
the information to attributes of the <p/> itself.

Seriously, LyX has failed to export common sense XMLized HTML for 14
years now, and I doubt they ever will. Best you can hope for is to
either switch to another authoring program, or repair LyX' mistakes
post-export. I think trying to repair this stuff from within your LyX
document is walking the highway to heartache.

Also, the good thing about the XML-parsing Python post-processor
approach is that, as time goes on, you can fix any problems newly
discovered and/or newly added by LyX: You're in control as long as they
continue to export well-formed XML HTML, which of course isn't a
for-sure thing.

SteveT

Steve Litt 
Summer 2022 featured book: Making Mental Models: Advanced Edition
http://www.troubleshooters.com/mmm


More information about the lyx-users mailing list