mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Rework how paragraph ids are handled.
Previously, an empty paragraph would always yield something like: <div><a id='magicparid-35' /></div> because we had no way to "defer" the anchor tag. Now this is wrapped into the div, in effect, and we abandon it all if there's no content.
This commit is contained in:
parent
c5a707ba74
commit
ad56bb7286
@ -2864,12 +2864,6 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
|
|||||||
|
|
||||||
xs.startParagraph(allowEmpty());
|
xs.startParagraph(allowEmpty());
|
||||||
|
|
||||||
if (!runparams.for_toc && runparams.html_make_pars) {
|
|
||||||
// generate a magic label for this paragraph
|
|
||||||
string const attr = "id='" + magicLabel() + "'";
|
|
||||||
xs << html::CompTag("a", attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
FontInfo font_old =
|
FontInfo font_old =
|
||||||
style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
|
style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ namespace lyx {
|
|||||||
|
|
||||||
namespace html {
|
namespace html {
|
||||||
|
|
||||||
|
|
||||||
docstring escapeChar(char_type c, XHTMLStream::EscapeSettings e)
|
docstring escapeChar(char_type c, XHTMLStream::EscapeSettings e)
|
||||||
{
|
{
|
||||||
docstring str;
|
docstring str;
|
||||||
@ -174,6 +173,19 @@ docstring StartTag::asEndTag() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
docstring ParTag::asTag() const
|
||||||
|
{
|
||||||
|
docstring output = StartTag::asTag();
|
||||||
|
|
||||||
|
if (parid_.empty())
|
||||||
|
return output;
|
||||||
|
|
||||||
|
string const pattr = "id='" + parid_ + "'";
|
||||||
|
output += html::CompTag("a", pattr).asTag();
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
docstring EndTag::asEndTag() const
|
docstring EndTag::asEndTag() const
|
||||||
{
|
{
|
||||||
string output = "</" + tag_ + ">";
|
string output = "</" + tag_ + ">";
|
||||||
@ -398,6 +410,15 @@ XHTMLStream & XHTMLStream::operator<<(html::StartTag const & tag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
XHTMLStream & XHTMLStream::operator<<(html::ParTag const & tag)
|
||||||
|
{
|
||||||
|
if (tag.tag_.empty())
|
||||||
|
return *this;
|
||||||
|
pending_tags_.push_back(makeTagPtr(tag));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag)
|
XHTMLStream & XHTMLStream::operator<<(html::CompTag const & tag)
|
||||||
{
|
{
|
||||||
if (tag.tag_.empty())
|
if (tag.tag_.empty())
|
||||||
@ -611,6 +632,28 @@ void openTag(XHTMLStream & xs, Layout const & lay,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void openParTag(XHTMLStream & xs, Layout const & lay,
|
||||||
|
std::string parlabel)
|
||||||
|
{
|
||||||
|
xs << html::ParTag(lay.htmltag(), lay.htmlattr(), parlabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void openParTag(XHTMLStream & xs, Layout const & lay,
|
||||||
|
ParagraphParameters const & params,
|
||||||
|
std::string parlabel)
|
||||||
|
{
|
||||||
|
// FIXME Are there other things we should handle here?
|
||||||
|
string const align = alignmentToCSS(params.align());
|
||||||
|
if (align.empty()) {
|
||||||
|
openParTag(xs, lay, parlabel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string attrs = lay.htmlattr() + " style='text-align: " + align + ";'";
|
||||||
|
xs << html::ParTag(lay.htmltag(), attrs, parlabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void closeTag(XHTMLStream & xs, Layout const & lay)
|
inline void closeTag(XHTMLStream & xs, Layout const & lay)
|
||||||
{
|
{
|
||||||
xs << html::EndTag(lay.htmltag());
|
xs << html::EndTag(lay.htmltag());
|
||||||
@ -721,8 +764,12 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
|
|||||||
// multiple paragraphs.
|
// multiple paragraphs.
|
||||||
bool const opened = runparams.html_make_pars &&
|
bool const opened = runparams.html_make_pars &&
|
||||||
(par != pbegin || !runparams.html_in_par);
|
(par != pbegin || !runparams.html_in_par);
|
||||||
|
bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
|
||||||
|
|
||||||
if (opened)
|
if (opened)
|
||||||
openTag(xs, lay, par->params());
|
openParTag(xs, lay, par->params(),
|
||||||
|
make_parid ? par->magicLabel() : "");
|
||||||
|
|
||||||
docstring const deferred =
|
docstring const deferred =
|
||||||
par->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)));
|
par->simpleLyXHTMLOnePar(buf, xs, runparams, text.outerFont(distance(begin, par)));
|
||||||
|
|
||||||
@ -789,7 +836,7 @@ ParagraphList::const_iterator makeEnvironment(Buffer const & buf,
|
|||||||
depth_type const origdepth = pbegin->params().depth();
|
depth_type const origdepth = pbegin->params().depth();
|
||||||
|
|
||||||
// open tag for this environment
|
// open tag for this environment
|
||||||
openTag(xs, bstyle);
|
openParTag(xs, bstyle, pbegin->magicLabel());
|
||||||
xs << html::CR();
|
xs << html::CR();
|
||||||
|
|
||||||
// we will on occasion need to remember a layout from before.
|
// we will on occasion need to remember a layout from before.
|
||||||
@ -930,7 +977,10 @@ void makeCommand(Buffer const & buf,
|
|||||||
buf.masterBuffer()->params().
|
buf.masterBuffer()->params().
|
||||||
documentClass().counters().step(style.counter, OutputUpdate);
|
documentClass().counters().step(style.counter, OutputUpdate);
|
||||||
|
|
||||||
openTag(xs, style, pbegin->params());
|
bool const make_parid = !runparams.for_toc && runparams.html_make_pars;
|
||||||
|
|
||||||
|
openParTag(xs, style, pbegin->params(),
|
||||||
|
make_parid ? pbegin->magicLabel() : "");
|
||||||
|
|
||||||
// Label around sectioning number:
|
// Label around sectioning number:
|
||||||
// FIXME Probably need to account for LABEL_MANUAL
|
// FIXME Probably need to account for LABEL_MANUAL
|
||||||
|
@ -32,17 +32,20 @@ class Text;
|
|||||||
namespace html {
|
namespace html {
|
||||||
/// Attributes will be escaped automatically and so should NOT
|
/// Attributes will be escaped automatically and so should NOT
|
||||||
/// be escaped before being passed to the constructor.
|
/// be escaped before being passed to the constructor.
|
||||||
struct StartTag {
|
struct StartTag
|
||||||
|
{
|
||||||
///
|
///
|
||||||
explicit StartTag(std::string const & tag) : tag_(tag), keepempty_(false) {}
|
explicit StartTag(std::string const & tag) : tag_(tag), keepempty_(false) {}
|
||||||
///
|
///
|
||||||
explicit StartTag(std::string const & tag, std::string const & attr,
|
explicit StartTag(std::string const & tag, std::string const & attr,
|
||||||
bool keepempty = false)
|
bool keepempty = false)
|
||||||
: tag_(tag), attr_(attr), keepempty_(keepempty) {}
|
: tag_(tag), attr_(attr), keepempty_(keepempty) {}
|
||||||
|
///
|
||||||
|
~StartTag() {}
|
||||||
/// <tag_ attr_>
|
/// <tag_ attr_>
|
||||||
docstring asTag() const;
|
virtual docstring asTag() const;
|
||||||
/// </tag_>
|
/// </tag_>
|
||||||
docstring asEndTag() const;
|
virtual docstring asEndTag() const;
|
||||||
///
|
///
|
||||||
std::string tag_;
|
std::string tag_;
|
||||||
///
|
///
|
||||||
@ -53,7 +56,25 @@ struct StartTag {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct EndTag {
|
/// A special case of StartTag, used exclusively for tags that wrap paragraphs.
|
||||||
|
struct ParTag : public StartTag
|
||||||
|
{
|
||||||
|
///
|
||||||
|
ParTag(std::string const & tag, std::string const & attr,
|
||||||
|
std::string const & parid)
|
||||||
|
: StartTag(tag, attr), parid_(parid)
|
||||||
|
{}
|
||||||
|
///
|
||||||
|
~ParTag() {}
|
||||||
|
///
|
||||||
|
docstring asTag() const;
|
||||||
|
/// the "magic par label" for this paragraph
|
||||||
|
std::string parid_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct EndTag
|
||||||
|
{
|
||||||
///
|
///
|
||||||
explicit EndTag(std::string tag) : tag_(tag) {}
|
explicit EndTag(std::string tag) : tag_(tag) {}
|
||||||
/// </tag_>
|
/// </tag_>
|
||||||
@ -63,14 +84,11 @@ struct EndTag {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// FIXME XHTML
|
|
||||||
// We need to allow these to be deferrable, which means it should
|
|
||||||
// inherit from StartTag. This is probably better, anyway, but we'll
|
|
||||||
// need to re-work a bit of code....
|
|
||||||
/// Tags like <img />
|
/// Tags like <img />
|
||||||
/// Attributes will be escaped automatically and so should NOT
|
/// Attributes will be escaped automatically and so should NOT
|
||||||
/// be escaped before being passed to the constructor.
|
/// be escaped before being passed to the constructor.
|
||||||
struct CompTag {
|
struct CompTag
|
||||||
|
{
|
||||||
///
|
///
|
||||||
explicit CompTag(std::string const & tag)
|
explicit CompTag(std::string const & tag)
|
||||||
: tag_(tag) {}
|
: tag_(tag) {}
|
||||||
@ -127,6 +145,8 @@ public:
|
|||||||
///
|
///
|
||||||
XHTMLStream & operator<<(html::CompTag const &);
|
XHTMLStream & operator<<(html::CompTag const &);
|
||||||
///
|
///
|
||||||
|
XHTMLStream & operator<<(html::ParTag const &);
|
||||||
|
///
|
||||||
XHTMLStream & operator<<(html::CR const &);
|
XHTMLStream & operator<<(html::CR const &);
|
||||||
///
|
///
|
||||||
enum EscapeSettings {
|
enum EscapeSettings {
|
||||||
|
Loading…
Reference in New Issue
Block a user