≡

wincent.dev

  • Products
  • Blog
  • Wiki
  • Issues
You are viewing an historical archive of past issues. Please report new issues to the appropriate project issue tracker on GitHub.
Home » Issues » Support ticket #2216

Support ticket #2216: Setting attributes & floating images

Kind support ticket
Product wikitext
When Created 2015-07-18T23:51:35Z, updated 2015-07-24T18:07:17Z
Status open
Reporter anonymous
Tags no tags

Description

Hi,

How can I set attributes of Wikitext in a rails 4 application ?

I'm using wikitext to render the content of a page (not all the page) so I call Wikitext like that :

<%= @codex.content.to_wikitext %>

So, how can I set attributes (like internal links prefix) in the entire application ? I'm sorry, but I didn't well understood how to do it.

And, is there an easy way to create floating image ? I mean, in a Wiki, there is often image next to the text. Is there easy way to add a "floating left" or "floating right" attribute ? Or to add a css class who do it ?

Sincerely,

Comments

  1. Greg Hurrell 2015-07-21T18:34:07Z

    Initialization

    If you're using this in the context of a Rails app, you could put initialization in a config/initializers/wikitext.rb file; here's an example from a project of mine:

    # Override example "wikitext/preprocess" that comes with wikitext gem.
    class String
      def wikitext_preprocess
        self.
          # autolink hashtags, but only ones containing at least one letter
          gsub(
            %r{
              (^|\s)                           # only at start of line/after space
              \#(                              # will match a hashtag
                (?:[a-z0-9]*[a-z][a-z0-9]*)+   # "word" containing at least 1 letter
                (?:\.[a-z0-9]*[a-z][a-z0-9]*)* # 0 or more ".word"
              )\b
            }ix,
            '\1[/tags/\2 #\2]'
          ).
          # same as in wikitext/preprocess:
          gsub(/\b(bug|issue|request|ticket) #(\d+)/i, '[/issues/\2 \1 #\2]')
      end
    end
    

    Note that the #to_wikitext method will use a shared parser instance by default, so you can just configure that eg. you could do:

    parser = Wikitext::Parser.shared_parser
    parser.internal_link_prefix = '/foo/'

    Floating

    At the moment there is no built-in way to do this. You could target img tags via CSS, but in order to be flexible we'd need to provide a way to allow a class to be included in the image syntax. I haven't really thought about what that should be, but I'm guessing something like {left:image.jpg} or similar. The question I'd wonder would be, should we allow arbitrary classnames, or restrict it to a whitelist? Whatever it was, it should be gated behind an option, for security.

  2. anonymous 2015-07-24T15:22:03Z

    Hi,

    I think that providing a limited number of class (left, right, hidden) by default could be a good idea, and in a second time, adding an option to accept non standard class (arbitrary classnames) could cover most of the cases. But as you said, it could be problematic and bad used by the user so an option for the developer is essential to avoid problems.

    Just a question : does wikitext come with a CSS file ? If it's not the case, maybe leave to the user the choice of the class to apply (I'm thinking to bootstrap users like me for example).

  3. Greg Hurrell 2015-07-24T18:07:17Z

    does wikitext come with a CSS file

    Nope, it's not opinionated about how things should be styled.

Add a comment

Comments are now closed for this issue.

  • contact
  • legal

Menu

  • Blog
  • Wiki
  • Issues
  • Snippets