2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetLabel.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetLabel.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2008-03-02 15:27:35 +00:00
|
|
|
#include "InsetRef.h"
|
|
|
|
|
2008-03-02 17:04:10 +00:00
|
|
|
#include "buffer_funcs.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2010-01-20 19:03:17 +00:00
|
|
|
#include "BufferParams.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2008-11-16 19:19:07 +00:00
|
|
|
#include "CutAndPaste.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
2008-11-16 19:19:07 +00:00
|
|
|
#include "FuncStatus.h"
|
2008-03-02 15:27:35 +00:00
|
|
|
#include "InsetIterator.h"
|
2010-01-20 19:03:17 +00:00
|
|
|
#include "Language.h"
|
2010-02-09 16:11:13 +00:00
|
|
|
#include "LyX.h"
|
2008-02-27 15:23:22 +00:00
|
|
|
#include "ParIterator.h"
|
2019-05-09 23:35:40 +00:00
|
|
|
#include "xml.h"
|
2019-03-14 13:24:43 +00:00
|
|
|
#include "texstream.h"
|
2008-02-27 15:23:22 +00:00
|
|
|
#include "Text.h"
|
2010-01-20 19:03:17 +00:00
|
|
|
#include "TextClass.h"
|
2008-02-27 15:23:22 +00:00
|
|
|
#include "TocBackend.h"
|
2003-02-27 16:24:14 +00:00
|
|
|
|
2010-01-28 17:37:22 +00:00
|
|
|
#include "mathed/InsetMathHull.h"
|
|
|
|
#include "mathed/InsetMathRef.h"
|
|
|
|
|
2008-03-02 15:27:35 +00:00
|
|
|
#include "frontends/alert.h"
|
|
|
|
|
2008-03-02 17:04:10 +00:00
|
|
|
#include "support/convert.h"
|
2008-03-02 15:27:35 +00:00
|
|
|
#include "support/gettext.h"
|
|
|
|
#include "support/lstrings.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/lyxalgo.h"
|
2003-10-10 21:08:55 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
using namespace std;
|
2007-12-12 19:57:42 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2009-11-08 16:10:34 +00:00
|
|
|
InsetLabel::InsetLabel(Buffer * buf, InsetCommandParams const & p)
|
2010-10-29 00:46:21 +00:00
|
|
|
: InsetCommand(buf, p)
|
2010-03-15 08:55:58 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2008-03-03 17:58:26 +00:00
|
|
|
void InsetLabel::initView()
|
2008-03-02 18:14:12 +00:00
|
|
|
{
|
2012-09-19 08:14:56 +00:00
|
|
|
// This seems to be used only for inset creation.
|
|
|
|
// Therefore we do not update refs here, since this would
|
|
|
|
// erroneously change refs from existing duplicate labels
|
|
|
|
// (#8141).
|
|
|
|
updateLabel(getParam("name"));
|
2008-03-02 18:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-06 17:40:51 +00:00
|
|
|
void InsetLabel::uniqueLabel(docstring & label) const
|
2008-03-02 17:04:10 +00:00
|
|
|
{
|
2011-07-06 17:40:51 +00:00
|
|
|
docstring const new_label = label;
|
2008-03-03 08:19:36 +00:00
|
|
|
int i = 1;
|
2018-12-29 09:08:02 +00:00
|
|
|
bool ambiguous = false;
|
|
|
|
while (buffer().activeLabel(label)) {
|
2008-03-02 17:04:10 +00:00
|
|
|
label = new_label + '-' + convert<docstring>(i);
|
|
|
|
++i;
|
2018-12-29 09:08:02 +00:00
|
|
|
ambiguous = true;
|
2008-03-02 17:04:10 +00:00
|
|
|
}
|
2018-12-29 09:08:02 +00:00
|
|
|
if (ambiguous) {
|
2008-03-03 08:19:36 +00:00
|
|
|
// Warn the user that the label has been changed to something else.
|
|
|
|
frontend::Alert::warning(_("Label names must be unique!"),
|
|
|
|
bformat(_("The label %1$s already exists,\n"
|
2008-03-03 13:58:18 +00:00
|
|
|
"it will be changed to %2$s."), new_label, label));
|
2011-07-06 17:40:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-25 13:40:30 +00:00
|
|
|
void InsetLabel::updateLabel(docstring const & new_label, bool const active)
|
2011-07-06 17:40:51 +00:00
|
|
|
{
|
|
|
|
docstring label = new_label;
|
2019-01-25 13:40:30 +00:00
|
|
|
if (active)
|
|
|
|
uniqueLabel(label);
|
2011-07-06 17:40:51 +00:00
|
|
|
setParam("name", label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetLabel::updateLabelAndRefs(docstring const & new_label,
|
|
|
|
Cursor * cursor)
|
|
|
|
{
|
|
|
|
docstring const old_label = getParam("name");
|
|
|
|
docstring label = new_label;
|
|
|
|
uniqueLabel(label);
|
|
|
|
if (label == old_label)
|
2011-06-29 13:42:55 +00:00
|
|
|
return;
|
2008-03-03 08:19:36 +00:00
|
|
|
|
2017-12-13 10:10:49 +00:00
|
|
|
// This handles undo groups automagically
|
|
|
|
UndoGroupHelper ugh(&buffer());
|
2011-07-06 18:52:56 +00:00
|
|
|
if (cursor)
|
|
|
|
cursor->recordUndo();
|
2019-12-31 11:29:53 +00:00
|
|
|
if (buffer().masterParams().track_changes) {
|
2019-12-29 10:01:18 +00:00
|
|
|
// With change tracking, we insert a new label and
|
|
|
|
// delete the old one
|
|
|
|
InsetCommandParams p(LABEL_CODE, "label");
|
|
|
|
p["name"] = label;
|
|
|
|
string const data = InsetCommand::params2string(p);
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_FORWARD));
|
|
|
|
} else
|
|
|
|
setParam("name", label);
|
2011-07-06 17:40:51 +00:00
|
|
|
updateReferences(old_label, label);
|
|
|
|
}
|
|
|
|
|
2008-03-02 17:04:10 +00:00
|
|
|
|
2011-07-06 17:40:51 +00:00
|
|
|
void InsetLabel::updateReferences(docstring const & old_label,
|
|
|
|
docstring const & new_label)
|
|
|
|
{
|
2017-07-04 14:34:34 +00:00
|
|
|
UndoGroupHelper ugh;
|
2019-12-31 11:29:53 +00:00
|
|
|
if (buffer().masterParams().track_changes) {
|
|
|
|
// With change tracking, we insert a new ref and
|
|
|
|
// delete the old one
|
|
|
|
lyx::dispatch(FuncRequest(LFUN_MASTER_BUFFER_FORALL,
|
|
|
|
"inset-forall Ref inset-modify ref changetarget "
|
|
|
|
+ old_label + " " + new_label));
|
|
|
|
} else {
|
|
|
|
for (auto const & p: buffer().references(old_label)) {
|
|
|
|
ugh.resetBuffer(p.second.buffer());
|
|
|
|
CursorData(p.second).recordUndo();
|
|
|
|
if (p.first->lyxCode() == MATH_REF_CODE) {
|
|
|
|
InsetMathRef * mi = p.first->asInsetMath()->asRefInset();
|
|
|
|
mi->changeTarget(new_label);
|
|
|
|
} else {
|
|
|
|
InsetCommand * ref = p.first->asInsetCommand();
|
|
|
|
ref->setParam("reference", new_label);
|
|
|
|
}
|
2008-09-17 16:28:33 +00:00
|
|
|
}
|
2008-03-03 09:35:26 +00:00
|
|
|
}
|
2008-03-02 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
ParamInfo const & InsetLabel::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo param_info_;
|
2008-11-16 16:43:49 +00:00
|
|
|
if (param_info_.empty())
|
2010-02-13 13:08:32 +00:00
|
|
|
param_info_.add("name", ParamInfo::LATEX_REQUIRED,
|
|
|
|
ParamInfo::HANDLING_ESCAPE);
|
2008-02-23 22:01:02 +00:00
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetLabel::screenLabel() const
|
2003-10-12 18:54:12 +00:00
|
|
|
{
|
2008-03-03 13:31:44 +00:00
|
|
|
return screen_label_;
|
2003-10-12 18:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-06 12:23:01 +00:00
|
|
|
void InsetLabel::updateBuffer(ParIterator const & par, UpdateType utype, bool const /*deleted*/)
|
2008-03-02 15:27:35 +00:00
|
|
|
{
|
|
|
|
docstring const & label = getParam("name");
|
2018-12-29 09:08:02 +00:00
|
|
|
|
2018-12-31 17:32:38 +00:00
|
|
|
// Check if this one is active (i.e., neither deleted with change-tracking
|
|
|
|
// nor in an inset that does not produce output, such as notes or inactive branches)
|
2018-12-29 09:08:02 +00:00
|
|
|
Paragraph const & para = par.paragraph();
|
2018-12-31 17:32:38 +00:00
|
|
|
bool active = !para.isDeleted(par.pos()) && para.inInset().producesOutput();
|
|
|
|
// If not, check whether we are in a deleted/non-outputting inset
|
2018-12-30 17:27:28 +00:00
|
|
|
if (active) {
|
|
|
|
for (size_type sl = 0 ; sl < par.depth() ; ++sl) {
|
|
|
|
Paragraph const & outer_par = par[sl].paragraph();
|
2018-12-31 17:32:38 +00:00
|
|
|
if (outer_par.isDeleted(par[sl].pos())
|
|
|
|
|| !outer_par.inInset().producesOutput()) {
|
2018-12-30 17:27:28 +00:00
|
|
|
active = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-29 09:08:02 +00:00
|
|
|
|
|
|
|
if (buffer().activeLabel(label) && active) {
|
|
|
|
// Problem: We already have an active InsetLabel with the same name!
|
2008-03-03 13:31:44 +00:00
|
|
|
screen_label_ = _("DUPLICATE: ") + label;
|
2008-03-02 15:27:35 +00:00
|
|
|
return;
|
2008-03-03 13:31:44 +00:00
|
|
|
}
|
2018-12-29 09:08:02 +00:00
|
|
|
buffer().setInsetLabel(label, this, active);
|
2008-03-03 13:31:44 +00:00
|
|
|
screen_label_ = label;
|
2010-01-20 19:03:17 +00:00
|
|
|
|
2010-11-29 17:14:38 +00:00
|
|
|
if (utype == OutputUpdate) {
|
2010-01-20 19:03:17 +00:00
|
|
|
// save info on the active counter
|
2017-07-03 17:53:14 +00:00
|
|
|
Counters const & cnts =
|
2010-01-20 19:03:17 +00:00
|
|
|
buffer().masterBuffer()->params().documentClass().counters();
|
|
|
|
active_counter_ = cnts.currentCounter();
|
|
|
|
Language const * lang = par->getParLanguage(buffer().params());
|
2010-01-20 20:33:36 +00:00
|
|
|
if (lang && !active_counter_.empty()) {
|
2010-01-20 19:03:17 +00:00
|
|
|
counter_value_ = cnts.theCounter(active_counter_, lang->code());
|
2010-01-20 20:33:36 +00:00
|
|
|
pretty_counter_ = cnts.prettyCounter(active_counter_, lang->code());
|
|
|
|
} else {
|
2010-11-29 19:11:38 +00:00
|
|
|
counter_value_ = from_ascii("#");
|
|
|
|
pretty_counter_ = from_ascii("#");
|
2010-01-20 20:33:36 +00:00
|
|
|
}
|
2010-01-20 19:03:17 +00:00
|
|
|
}
|
2008-03-02 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-27 06:05:00 +00:00
|
|
|
void InsetLabel::addToToc(DocIterator const & cpit, bool output_active,
|
2018-12-31 17:30:20 +00:00
|
|
|
UpdateType, TocBackend & backend) const
|
2008-02-27 15:23:22 +00:00
|
|
|
{
|
2008-03-02 15:27:35 +00:00
|
|
|
docstring const & label = getParam("name");
|
2018-12-29 09:08:02 +00:00
|
|
|
|
2018-12-31 17:30:20 +00:00
|
|
|
// inactive labels get a cross mark
|
|
|
|
if (buffer().insetLabel(label, true) != this)
|
|
|
|
output_active = false;
|
|
|
|
|
|
|
|
// We put both active and inactive labels to the outliner
|
2017-01-13 10:06:48 +00:00
|
|
|
shared_ptr<Toc> toc = backend.toc("label");
|
2018-12-31 17:30:20 +00:00
|
|
|
toc->push_back(TocItem(cpit, 0, screen_label_, output_active));
|
|
|
|
// The refs get assigned only to the active label. If no active one exists,
|
|
|
|
// assign the (BROKEN) refs to the first inactive one.
|
|
|
|
if (buffer().insetLabel(label, true) == this || !buffer().activeLabel(label)) {
|
2017-11-29 13:52:50 +00:00
|
|
|
for (auto const & p : buffer().references(label)) {
|
|
|
|
DocIterator const ref_pit(p.second);
|
|
|
|
if (p.first->lyxCode() == MATH_REF_CODE)
|
2015-09-01 16:08:35 +00:00
|
|
|
toc->push_back(TocItem(ref_pit, 1,
|
2017-11-29 13:52:50 +00:00
|
|
|
p.first->asInsetMath()->asRefInset()->screenLabel(),
|
2015-09-01 16:08:35 +00:00
|
|
|
output_active));
|
|
|
|
else
|
|
|
|
toc->push_back(TocItem(ref_pit, 1,
|
2017-11-29 13:52:50 +00:00
|
|
|
static_cast<InsetRef *>(p.first)->getTOCString(),
|
2020-03-14 15:29:53 +00:00
|
|
|
static_cast<InsetRef *>(p.first)->outputActive()));
|
2015-09-01 16:08:35 +00:00
|
|
|
}
|
2008-03-02 15:27:35 +00:00
|
|
|
}
|
2008-02-27 15:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-16 19:19:07 +00:00
|
|
|
bool InsetLabel::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
|
|
|
bool enabled;
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2014-02-11 10:00:20 +00:00
|
|
|
case LFUN_LABEL_INSERT_AS_REFERENCE:
|
|
|
|
case LFUN_LABEL_COPY_AS_REFERENCE:
|
2008-11-16 19:19:07 +00:00
|
|
|
enabled = true;
|
|
|
|
break;
|
2014-03-06 07:34:32 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
if (cmd.getArg(0) == "changetype") {
|
|
|
|
// this is handled by InsetCommand,
|
|
|
|
// but not by InsetLabel.
|
|
|
|
enabled = false;
|
|
|
|
break;
|
|
|
|
}
|
2017-08-12 07:06:29 +00:00
|
|
|
// no "changetype":
|
|
|
|
// fall through
|
2008-11-16 19:19:07 +00:00
|
|
|
default:
|
|
|
|
return InsetCommand::getStatus(cur, cmd, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
status.setEnabled(enabled);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-02-27 16:24:14 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
2003-03-07 21:44:48 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
2014-03-05 23:06:30 +00:00
|
|
|
// the only other option here is "changetype", and we
|
|
|
|
// do not have different types.
|
2014-03-05 22:43:41 +00:00
|
|
|
if (cmd.getArg(0) != "label") {
|
|
|
|
cur.undispatched();
|
|
|
|
return;
|
|
|
|
}
|
2007-10-19 17:22:55 +00:00
|
|
|
InsetCommandParams p(LABEL_CODE);
|
2006-11-02 10:16:21 +00:00
|
|
|
// FIXME UNICODE
|
2010-10-29 00:25:28 +00:00
|
|
|
InsetCommand::string2params(to_utf8(cmd.argument()), p);
|
2004-02-16 11:58:51 +00:00
|
|
|
if (p.getCmdName().empty()) {
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.noScreenUpdate();
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-12-08 09:24:04 +00:00
|
|
|
if (p["name"] != params()["name"]) {
|
2011-07-06 17:40:51 +00:00
|
|
|
// undo is handled in updateLabelAndRefs
|
|
|
|
updateLabelAndRefs(p["name"], &cur);
|
2010-12-08 09:24:04 +00:00
|
|
|
}
|
2010-07-09 14:37:00 +00:00
|
|
|
cur.forceBufferUpdate();
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-03-07 21:44:48 +00:00
|
|
|
}
|
2003-03-09 09:38:47 +00:00
|
|
|
|
2014-02-11 10:00:20 +00:00
|
|
|
case LFUN_LABEL_COPY_AS_REFERENCE: {
|
2008-11-16 19:19:07 +00:00
|
|
|
InsetCommandParams p(REF_CODE, "ref");
|
|
|
|
p["reference"] = getParam("name");
|
|
|
|
cap::clearSelection();
|
2009-11-08 15:53:21 +00:00
|
|
|
cap::copyInset(cur, new InsetRef(buffer_, p), getParam("name"));
|
2008-11-16 19:19:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-11 10:00:20 +00:00
|
|
|
case LFUN_LABEL_INSERT_AS_REFERENCE: {
|
2009-04-09 18:31:17 +00:00
|
|
|
InsetCommandParams p(REF_CODE, "ref");
|
|
|
|
p["reference"] = getParam("name");
|
2010-10-29 00:25:28 +00:00
|
|
|
string const data = InsetCommand::params2string(p);
|
2009-04-09 18:31:17 +00:00
|
|
|
lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-07 21:44:48 +00:00
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetCommand::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2000-05-19 16:46:01 +00:00
|
|
|
}
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
|
2019-03-14 13:24:43 +00:00
|
|
|
void InsetLabel::latex(otexstream & os, OutputParams const & runparams_in) const
|
|
|
|
{
|
|
|
|
OutputParams runparams = runparams_in;
|
|
|
|
docstring command = getCommand(runparams);
|
2020-03-29 15:47:59 +00:00
|
|
|
docstring const label = getParam("name");
|
|
|
|
if (buffer().params().output_changes
|
|
|
|
&& buffer().activeLabel(label)
|
|
|
|
&& buffer().insetLabel(label, true) != this) {
|
|
|
|
// this is a deleted label and we have a non-deleted with the same id
|
|
|
|
// rename it for output to prevent wrong references
|
|
|
|
docstring newlabel = label;
|
|
|
|
int i = 1;
|
|
|
|
while (buffer().insetLabel(newlabel)) {
|
|
|
|
newlabel = label + "-DELETED-" + convert<docstring>(i);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
command = subst(command, label, newlabel);
|
|
|
|
}
|
2019-03-14 13:24:43 +00:00
|
|
|
// In macros with moving arguments, such as \section,
|
|
|
|
// we store the label and output it after the macro (#2154)
|
|
|
|
if (runparams_in.postpone_fragile_stuff)
|
|
|
|
runparams_in.post_macro += command;
|
2019-03-14 13:38:08 +00:00
|
|
|
else {
|
2020-08-28 05:32:29 +00:00
|
|
|
// protect label in moving argument (#9404),
|
|
|
|
// but not in subfloat caption (#11950)
|
|
|
|
if (runparams.moving_arg
|
|
|
|
&& runparams.inFloat != OutputParams::SUBFLOAT)
|
2019-03-14 13:38:08 +00:00
|
|
|
os << "\\protect";
|
2019-03-14 13:24:43 +00:00
|
|
|
os << command;
|
2019-03-14 13:38:08 +00:00
|
|
|
}
|
2019-03-14 13:24:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetLabel::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const &, size_t) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
2007-02-24 14:35:38 +00:00
|
|
|
docstring const str = getParam("name");
|
2007-02-15 23:44:33 +00:00
|
|
|
os << '<' << str << '>';
|
|
|
|
return 2 + str.size();
|
2000-04-24 20:58:23 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
void InsetLabel::docbook(XMLStream & xs, OutputParams const & runparams) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2020-06-08 21:27:49 +00:00
|
|
|
// Output an anchor only if it has not been processed before.
|
2020-09-11 21:38:11 +00:00
|
|
|
docstring id = getParam("name");
|
|
|
|
docstring cleaned_id = xml::cleanID(id);
|
|
|
|
if (runparams.docbook_anchors_to_ignore.find(id) == runparams.docbook_anchors_to_ignore.end() &&
|
|
|
|
runparams.docbook_anchors_to_ignore.find(cleaned_id) == runparams.docbook_anchors_to_ignore.end()) {
|
|
|
|
docstring attr = from_utf8("xml:id=\"") + cleaned_id + from_utf8("\"");
|
2020-06-08 21:27:49 +00:00
|
|
|
xs << xml::CompTag("anchor", to_utf8(attr));
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2019-05-09 23:35:40 +00:00
|
|
|
docstring InsetLabel::xhtml(XMLStream & xs, OutputParams const &) const
|
2009-06-05 17:48:14 +00:00
|
|
|
{
|
2009-11-28 21:37:47 +00:00
|
|
|
// FIXME XHTML
|
|
|
|
// Unfortunately, the name attribute has been deprecated, so we have to use
|
2017-07-03 17:53:14 +00:00
|
|
|
// id here to get the document to validate as XHTML 1.1. This will cause a
|
2009-11-28 21:37:47 +00:00
|
|
|
// problem with some browsers, though, I'm sure. (Guess which!) So we will
|
2017-07-03 17:53:14 +00:00
|
|
|
// have to figure out what to do about this later.
|
2019-05-09 23:35:40 +00:00
|
|
|
docstring const attr = "id=\"" + xml::cleanAttr(getParam("name")) + '"';
|
|
|
|
xs << xml::CompTag("a", to_utf8(attr));
|
2009-06-12 17:23:17 +00:00
|
|
|
return docstring();
|
2009-06-05 17:48:14 +00:00
|
|
|
}
|
|
|
|
|
2009-11-28 21:37:47 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|