MichaelHatherly / Docile.jl

Julia package documentation system.
Other
40 stars 15 forks source link

register Formatter ? #128

Closed peter1000 closed 9 years ago

peter1000 commented 9 years ago

DOCS

Example:

import Docile.Formats, Markdown
const (fmt, md) = (Docile.Formats, Markdown)

immutable MarkdownFormatter <: fmt.AbstractFormatter end

fmt.parsedocs(::fmt.Format{MarkdownFormatter}, raw, mod, obj) = md.parse(raw)

When registering a package the format is then provided to PackageData.


It seems that this is not picked up: also your other examples suggests that one needs to set the [:format] meta.

Cache.getmeta(MetadataSyntax)[:format] = Formats.PlaintextFormatter

Dict(
        :format => MyCustomFormatter,
        # ...
    )
function extractor!(raw::AbstractString, m::Module, obj)
    str    = Formats.extractmeta!(raw, m, obj)
    format = findmeta(m, obj, :format)
    Formats.parsedocs(Formats.Format{format}(), str, m, obj)
end
Formats.parsedocs(::Formats.Format{MarkdownFormatter}, raw, mod, obj) =
    Base.Markdown.parse(raw)

Dict(
    :format => MarkdownFormatter
)

Question: did I miss something or does one have to set the meta [:format] do as in the examples?

What would be the best why to set it globally: ? .docile? if such is required maybe it should be mentioned at the top DOCS

MichaelHatherly commented 9 years ago

We're still using Legacy.parsedocs, which is not the same function as Formats.parsedocs.

I'll add the needed definitions later today if possible.

MichaelHatherly commented 9 years ago

Closed by 7fa03357a1d9f7d74904264f3f91a3f21f3589ea.

peter1000 commented 9 years ago
workspace()
import Docile.Formats
const (fmt, md) = (Docile.Formats, Markdown)
fmt.parsedocs(::fmt.Format{fmt.MarkdownFormatter}, raw, mod, obj) = md.parse(raw)

import Docile: Cache
objects = Cache.objects(Cache);
parsed =  Cache.getparsed(Cache, objects[5])
typeof(parsed)
julia> typeof(parsed)
Base.Markdown.MD

seems to work now: but from you commit I thought it should be default? Add MarkdownFormatter type. Make it default.

workspace()
import Docile: Cache
objects = Cache.objects(Cache);
parsed =  Cache.getparsed(Cache, objects[5])
typeof(parsed)
julia> typeof(parsed)
ASCIIString

Did I misinterpret the commit title?

MichaelHatherly commented 9 years ago

The actual definition of parsedocs that parses strings to markdown must be defined in Lexicon so we don't have to import all of Markdown into Docile.