Not logged in. · Lost password · Register
Page:  1  2  3  4  5  6  next 

All posts by zioth (77)

topic: tootip plugin be cut off  in the forum: General Help and Support Plugins
Avatar
zioth #1
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
Quote by Sirius:
And it works very well.

Good to hear! Thanks for helping me work out the kinks.

I was caught by surprise yesterday when I found that my plugin works in search -- the links in the search drop-down have tooltips with page summaries. Pretty useful. I like when I get an extra feature by accident. :)
topic: Syntax plugin to match every word on the page  in the forum: General Help and Support Plugins
Avatar
zioth #2
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 64099
I did some more debugging, and found that the problem is with the way regular expressions work. When two expressions both match in the lexer, the one that starts earlier wins.

Since (?:[\w'\-]+ *)+ always matches starting with the first word in a sentence, it always wins against my specific-phrase patterns, unless those patterns start at the beginning of the sentence too. I tried (?:[\w'\-]+ *)+? to make it non-greedy, but then it competes with itself, so it always matches exactly one word.

I want a regex that is non-greedy, so it never wins against other regexes, but I want it to be greedy when compared against itself. Any regex masters know whether that's possible?

I've also tried:
(?:(?:[\w'\-]+ *){1,1000})+?
(?:(?:[\w'\-]+ *)+)+?

Edit: More detail:

Here's an example of what I'm trying to do. The '|' separates my two plugins, and my example is in JavaScript for convenient debugging:

  • 'Once upon a time there were three bears'.match(/(\bupon a time\b)|(?:[\w\'\-]+ *)+?/g)
  • Returns: ["Once ", "upon a time", "there ", "were ", "three ", "bears"].
  • Expected: ["Once", "upon a time", "there were three bears"]
  • The first expression works, but the second breaks the string down into phrases, rather than words.

  • 'Once upon a time there were three bears'.match(/(\bupon a time\b)|(?:[\w\'\-]+ *)+/g)
  • Returns: ["Once upon a time there were three bears"].
  • Expected: ["Once", "upon a time", "there were three bears"]
  • The first expression is ignored entirely.

  • 'Once upon a time there were three bears'.match(/(\bOnce upon a time\b)|(?:[\w\'\-]+ *)+/g)
  • Returns: ["Once upon a time", "there were three bears"]
  • This is exactly what I want, but it only works if the first expression matches the beginning of the sentence.
This post was edited on 2018-12-28, 00:22 by zioth.
topic: Syntax plugin to match every word on the page  in the forum: General Help and Support Plugins
Avatar
zioth #3
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 64096
This also didn't help:
    function getAllowedTypes() {
        global $PARSER_MODES;
        return array_keys($PARSER_MODES);
    }
topic: Syntax plugin to match every word on the page  in the forum: General Help and Support Plugins
Avatar
zioth #4
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
Subject: Syntax plugin to match every word on the page
For my autolink4 plugin, I'm trying to analyze all page titles on the site, and link them on every other page. This could be done with a ton of addSpecialPattern() matches, but I'd quickly reach the limit of Doku's lexer, which can't handle more than 500-1000 patterns. Instead, I'd like to make my own parser, which searches every bit of text on the page not already processed by another syntax plugin, and look for strings that match page titles.

Is there a way to do this? I tried calling addSpecialPattern('(?:[\w\'\-]+\s*)+') to match all phrases, stopping at punctuation. I gave it a getSort() of 1000, in the hope that it wouldn't interfere with other syntax plugins, but it does. My other plugin with a getSort() of 999 no longer functions.

I also tried `function accepts($mode) {return true;}`. That helped a little, but still interfered with certain kinds of special patterns. I doubt it's the right solution anyway.

The alternative is to create an action plugin that post-processes the page, using Doku's lexer pattern to omit parts of the page that have already been worked on by syntax plugins, but that's very error-prone, if it's possible at all.

Another alternative is for me to submit a pull request to chunk the pattern in Doku's lexer, allowing it to accept more than 1000 special patterns. Though if there are 100,000 pages on the site, that's 100,000 special patterns, which means running through at least 100 huge regexes on every pass through the page.
topic: tootip plugin be cut off  in the forum: General Help and Support Plugins
Avatar
zioth #5
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 64068
Quote by Sirius on 2018-12-24, 01:35:
That would be awesome.

And it's done. You can now install a renderer plugin that adds a tooltip to every link on your site. See the documentation for details.

Enjoy!
topic: tootip plugin be cut off  in the forum: General Help and Support Plugins
Avatar
zioth #6
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 64066
Doku adds browser-native tooltips, which are usually just the wikilink (like a:b:c). I don't find those very useful. The autotooltip plugin pops up nicer looking tooltips that include the page title and abstract. It won't be useful for every wiki, but I like the previews. They keep me from having to click to a new page to remind myself what a term means.
This post was edited on 2018-12-24, 02:33 by zioth.
topic: Action plugins interacting with syntax sort order  in the forum: General Help and Support Plugins
Avatar
zioth #7
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
Subject: Action plugins interacting with syntax sort order
The getSort() method of syntax plugins does a very nice job of keeping plugins from stepping on each other's toes. Without it, my autolink4 plugin would inject links into other plugins' content, but since I have a sort of 999, it works.

The problem is, DokuWiki has a limit to the number of syntax rules due to the way it combines regular expressions. Somewhere between 500 and 1000, it stops working. An enhancement I'm considering could bring this number into the thousands, or even tens of thousands.

I could create an action plugin to do all the substitutions I need more efficiently and without breaking the parser, but is there any way to avoid stepping on syntax plugins?

Or is there a way to do this with a syntax plugin? I'd have to be able to match arbitrary words and phrases. I guess my match could be something like '(?:\b\w+){1,10}' or something.
topic: tootip plugin be cut off  in the forum: General Help and Support Plugins
Avatar
zioth #8
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 64042
Yay!

If anything else doesn't work, or if you have any suggestions for improvements, let me know! More enhancements are already on their way. My next update will include an option to add a tooltip to every link on your site.
topic: Trouble creating a renderer plugin  in the forum: General Help and Support Plugins
Avatar
zioth #9
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 64046
Thanks! That worked.

Renderer plugins would probably be more useful if they could stack on top of each other like syntax plugins. I want to override internallink. That shouldn't prevent someone else from overriding externallnk. Oh well.
topic: Trouble creating a renderer plugin  in the forum: General Help and Support Plugins
Avatar
zioth #10
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
Subject: Trouble creating a renderer plugin
Can anyone tell me what I'm doing wrong? My renderer plugin won't run, and I don't think it's loaded at all. If I add an obvious syntax error, it doesn't interfere with Doku's rendering.

The filename is renderer.php. It's in the top level directory of my plugin. The code roughly looks like this:

<?php
if (!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once DOKU_INC . 'inc/parser/xhtml.php';

class renderer_plugin_mypluginname extends Doku_Renderer_xhtml {
    function canRender($format){
        return $format == 'xhtml';
    }

    function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') {
        return 'BAD PLUGIN!';
    }
}
topic: tootip plugin be cut off  in the forum: General Help and Support Plugins
Avatar
zioth #11
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 63971
Looks like the template you're using doesn't have the normal dokuwiki page structure. I've adjusted the plugin to work with your template, and gave it some fallbacks that should guarantee it works with any template. Try one more time. I hope it works!

And thanks for helping me troubleshoot.
topic: tootip plugin be cut off  in the forum: General Help and Support Plugins
Avatar
zioth #12
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 63954
I was adding the tooltips to a page element that doesn't exist on many templates, including the default one! Pretty stupid of me. :)

If you update the plugin, it should work now.
topic: tootip plugin be cut off  in the forum: General Help and Support Plugins
Avatar
zioth #13
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 63951
There shouldn't be any dependencies, except jQuery (which is in the last several versions of DokuWiki). I've only tested my plugin on Greebo, so there's a chance it depends on that.

I'd be happy to debug your issue, if you point me to a page where it's not working. Other things that might be useful for debugging are:

- The syntax you use to create the autotooltip
- The url mode you use (doku.php?id, /a:b:c, or /a/b/c)
- The meta file for the page you're linking to. It can be found in data/meta/[path to page]/page.meta

Also try updating the plugin. I've made a lot of bug fixes in the past two days.
topic: Can render() append to the end of the document?  in the forum: General Help and Support Plugins
Avatar
zioth #14
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 63948
Yes, I know that now. I was just checking whether I could match the end of the document ($) without breaking anything. The answer was no.
topic: Can render() append to the end of the document?  in the forum: General Help and Support Plugins
Avatar
zioth #15
Member since Jul 2011 · 77 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 63944
I don't want to make users add a special pattern to the end of each wiki page. It's a strange requirement, and people (including me) will forget. I think I might be stuck with the Action plugin solution.

That is, unless I can add a special pattern that will capture the end of the document, without messing up other plugins. I just tried: $this->Lexer->addSpecialPattern('$', ...). It made the content fail to render at all.
Close Smaller – Larger + Reply to this post:
Special characters:
Page:  1  2  3  4  5  6  next 
Special queries
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-05-26, 22:35:23 (UTC +02:00)