From e5afe8db6669eb2395cbee3761053e38a0d05613 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Thu, 10 Dec 2009 20:03:35 +0000 Subject: [PATCH] This really gets the TOC working now. We auto-generate labels for the paragraphs the TOC targets, and link to them. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32461 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/layouts/stdtitle.inc | 6 ++++++ src/Paragraph.cpp | 17 +++++++++++++++++ src/Paragraph.h | 3 +++ src/insets/InsetTOC.cpp | 11 ++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/layouts/stdtitle.inc b/lib/layouts/stdtitle.inc index 2f7b48a58c..45c1c528da 100644 --- a/lib/layouts/stdtitle.inc +++ b/lib/layouts/stdtitle.inc @@ -34,6 +34,12 @@ AddToHTMLPreamble div.lyxtoc-4 { margin: 0em 0em 0em 1em; } div.lyxtoc-5 { margin: 0em 0em 0em 1em; } div.lyxtoc-6 { margin: 0em 0em 0em 1em; } + a.tocarrow { + font-weight: bold; + text-decoration: none; + color: #909090; + } + a.tocarrow:visited { color: #C0C0C0; } EndPreamble diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index f3ba6921cf..285fc4b273 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -2404,6 +2404,15 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf, std::string closing_tag; Layout const & style = *d->layout_; + + if (!fortoc + && style.toclevel != Layout::NOT_IN_TOC + && style.toclevel <= buf.params().tocdepth) { + // we need to generate a magic label for this paragraph + string const attr = "id='" + magicLabel() + "'"; + xs << CompTag("a", attr); + } + FontInfo font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font; @@ -3141,4 +3150,12 @@ bool Paragraph::isMisspelled(pos_type pos) const } +string Paragraph::magicLabel() const +{ + stringstream ss; + ss << "magicparlabel-" << id(); + return ss.str(); +} + + } // namespace lyx diff --git a/src/Paragraph.h b/src/Paragraph.h index 8bb275576f..485e239b66 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -424,6 +424,9 @@ public: /// Spellcheck word at position \p pos. /// \return true if pointed word is misspelled. bool isMisspelled(pos_type pos) const; + /// an automatically generated identifying label for this paragraph. + /// presently used only in the XHTML output routines. + std::string magicLabel() const; private: /// diff --git a/src/insets/InsetTOC.cpp b/src/insets/InsetTOC.cpp index bbae751763..84b5d6a38e 100644 --- a/src/insets/InsetTOC.cpp +++ b/src/insets/InsetTOC.cpp @@ -119,8 +119,10 @@ docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const int lastdepth = 0; for (; it != en; ++it) { Paragraph const & par = it->dit().innerParagraph(); - Font const dummy; int const depth = it->depth(); + if (depth > buffer().params().tocdepth) + continue; + Font const dummy; if (depth > lastdepth) { xs.cr(); // open as many tags as we need to open to get to this level @@ -149,7 +151,14 @@ docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const attr << "class='lyxtoc-" << depth << "'"; xs << StartTag("div", attr.str()); } + string const parattr = "href='#" + par.magicLabel() + "' class='tocarrow'"; par.simpleLyXHTMLOnePar(buffer(), xs, op, dummy, true); + xs << " "; + xs << StartTag("a", parattr); + // FIXME XHTML + // There ought to be a simple way to customize this. + xs << XHTMLStream::NextRaw() << "⇘"; + xs << EndTag("a"); } for (int i = lastdepth; i > 0; --i) xs << EndTag("div"); -- 2.39.5