public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* generate a source map on html generation?
@ 2013-10-18 10:57 Gallagher Pryor
       [not found] ` <e19a4bf3-6697-4a8b-bb57-6c99cfecbb9c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Gallagher Pryor @ 2013-10-18 10:57 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 1111 bytes --]

Is it possible to generate a source map upon html output from markdown?

I would like to use Pandoc to drive a web-based markdown editor and it 
would be nice to know what parts of the input markdown resulted in 
particular parts of the HTML output.

If this doesn't exist, could someone give pointers to where in the code 
base to start making changes for this to happen?  It looks like the parser 
maintains state regarding line numbers, but I'm a novice with Haskell and 
I'm having trouble tracing through things.

Thanks,

 - G

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e19a4bf3-6697-4a8b-bb57-6c99cfecbb9c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

[-- Attachment #2: Type: text/html, Size: 1472 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: generate a source map on html generation?
       [not found] ` <e19a4bf3-6697-4a8b-bb57-6c99cfecbb9c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2013-10-18 19:52   ` John MacFarlane
       [not found]     ` <20131018195258.GA75103-9Rnp8PDaXcadBw3G0RLmbRFnWt+6NQIA@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: John MacFarlane @ 2013-10-18 19:52 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

It's not possible with current code.  The markdown parser has access to
position information.  However, there's no slot in the Pandoc data
structure to store this, so it just gets thrown away and the writers
don't have access to it.

It would require fairly substantial changes to make room for this.

Perhaps the least intrusive way to do it would be to have the markdown
reader wrap every inline element in a Span element with the attributes
giving position information.

Perhaps it would be sufficient to wrap 'Str' elements this way.

This would require modifying the 'str' function so that instead of

   return $ return $ B.str result

it has something like

   return $ return $ B.spanWith
     ("",[],[("data-line",lineNum),("data-column",colNum)) $ B.str result

You can get lineNum and colNum this way:

    pos <- getPosition
    let lineNum = show $ sourceLine pos
    let colNum  = show $ sourceColumn pos

If you did all this, every content word would be wrapped in an HTML
span tag with attributes that give the source position.

+++ Gallagher Pryor [Oct 18 13 03:57 ]:
> Is it possible to generate a source map upon html output from markdown?
> 
> I would like to use Pandoc to drive a web-based markdown editor and it 
> would be nice to know what parts of the input markdown resulted in 
> particular parts of the HTML output.
> 
> If this doesn't exist, could someone give pointers to where in the code 
> base to start making changes for this to happen?  It looks like the parser 
> maintains state regarding line numbers, but I'm a novice with Haskell and 
> I'm having trouble tracing through things.
> 
> Thanks,
> 
>  - G
> 
> -- 
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e19a4bf3-6697-4a8b-bb57-6c99cfecbb9c%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: generate a source map on html generation?
       [not found]     ` <20131018195258.GA75103-9Rnp8PDaXcadBw3G0RLmbRFnWt+6NQIA@public.gmane.org>
@ 2013-10-18 21:40       ` John MacFarlane
       [not found]         ` <20131018214049.GA8345-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: John MacFarlane @ 2013-10-18 21:40 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Sorry, there was a typo.  Here's the idea:

     pos <- getPosition
     let lineNum = show $ sourceLine pos
     let colNum  = show $ sourceColumn pos
     return $ return $ B.spanWith
       ("",[],[("data-line",lineNum),("data-column",colNum)]) $ B.str result


+++ John MacFarlane [Oct 18 13 12:52 ]:
> It's not possible with current code.  The markdown parser has access to
> position information.  However, there's no slot in the Pandoc data
> structure to store this, so it just gets thrown away and the writers
> don't have access to it.
> 
> It would require fairly substantial changes to make room for this.
> 
> Perhaps the least intrusive way to do it would be to have the markdown
> reader wrap every inline element in a Span element with the attributes
> giving position information.
> 
> Perhaps it would be sufficient to wrap 'Str' elements this way.
> 
> This would require modifying the 'str' function so that instead of
> 
>    return $ return $ B.str result
> 
> it has something like
> 
>    return $ return $ B.spanWith
>      ("",[],[("data-line",lineNum),("data-column",colNum)) $ B.str result
> 
> You can get lineNum and colNum this way:
> 
>     pos <- getPosition
>     let lineNum = show $ sourceLine pos
>     let colNum  = show $ sourceColumn pos
> 
> If you did all this, every content word would be wrapped in an HTML
> span tag with attributes that give the source position.
> 
> +++ Gallagher Pryor [Oct 18 13 03:57 ]:
> > Is it possible to generate a source map upon html output from markdown?
> > 
> > I would like to use Pandoc to drive a web-based markdown editor and it 
> > would be nice to know what parts of the input markdown resulted in 
> > particular parts of the HTML output.
> > 
> > If this doesn't exist, could someone give pointers to where in the code 
> > base to start making changes for this to happen?  It looks like the parser 
> > maintains state regarding line numbers, but I'm a novice with Haskell and 
> > I'm having trouble tracing through things.
> > 
> > Thanks,
> > 
> >  - G
> > 
> > -- 
> > You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e19a4bf3-6697-4a8b-bb57-6c99cfecbb9c%40googlegroups.com.
> > For more options, visit https://groups.google.com/groups/opt_out.
> 
> -- 
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/20131018195258.GA75103%40Johns-MacBook-Pro.local.
> For more options, visit https://groups.google.com/groups/opt_out.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: generate a source map on html generation?
       [not found]         ` <20131018214049.GA8345-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
@ 2013-10-20 21:06           ` Gallagher Pryor
  0 siblings, 0 replies; 4+ messages in thread
From: Gallagher Pryor @ 2013-10-20 21:06 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 5117 bytes --]

I will try this approach, see if it has the effect you describe, and report
my findings, here.

It may be relatively easy to do a post processing step after a pandoc run
to reduce the number of position-indicating span elements. If that pans
out, I'll post that back here, as well.

Thank you very much for the reply!

 - G


On Fri, Oct 18, 2013 at 4:40 PM, John MacFarlane <fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:

> Sorry, there was a typo.  Here's the idea:
>
>      pos <- getPosition
>      let lineNum = show $ sourceLine pos
>      let colNum  = show $ sourceColumn pos
>      return $ return $ B.spanWith
>        ("",[],[("data-line",lineNum),("data-column",colNum)]) $ B.str
> result
>
>
> +++ John MacFarlane [Oct 18 13 12:52 ]:
> > It's not possible with current code.  The markdown parser has access to
> > position information.  However, there's no slot in the Pandoc data
> > structure to store this, so it just gets thrown away and the writers
> > don't have access to it.
> >
> > It would require fairly substantial changes to make room for this.
> >
> > Perhaps the least intrusive way to do it would be to have the markdown
> > reader wrap every inline element in a Span element with the attributes
> > giving position information.
> >
> > Perhaps it would be sufficient to wrap 'Str' elements this way.
> >
> > This would require modifying the 'str' function so that instead of
> >
> >    return $ return $ B.str result
> >
> > it has something like
> >
> >    return $ return $ B.spanWith
> >      ("",[],[("data-line",lineNum),("data-column",colNum)) $ B.str result
> >
> > You can get lineNum and colNum this way:
> >
> >     pos <- getPosition
> >     let lineNum = show $ sourceLine pos
> >     let colNum  = show $ sourceColumn pos
> >
> > If you did all this, every content word would be wrapped in an HTML
> > span tag with attributes that give the source position.
> >
> > +++ Gallagher Pryor [Oct 18 13 03:57 ]:
> > > Is it possible to generate a source map upon html output from markdown?
> > >
> > > I would like to use Pandoc to drive a web-based markdown editor and it
> > > would be nice to know what parts of the input markdown resulted in
> > > particular parts of the HTML output.
> > >
> > > If this doesn't exist, could someone give pointers to where in the code
> > > base to start making changes for this to happen?  It looks like the
> parser
> > > maintains state regarding line numbers, but I'm a novice with Haskell
> and
> > > I'm having trouble tracing through things.
> > >
> > > Thanks,
> > >
> > >  - G
> > >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups "pandoc-discuss" group.
> > > To unsubscribe from this group and stop receiving emails from it, send
> an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > > To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > > To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/e19a4bf3-6697-4a8b-bb57-6c99cfecbb9c%40googlegroups.com
> .
> > > For more options, visit https://groups.google.com/groups/opt_out.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "pandoc-discuss" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/20131018195258.GA75103%40Johns-MacBook-Pro.local
> .
> > For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "pandoc-discuss" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/pandoc-discuss/pDs41Da4KjA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/20131018214049.GA8345%40protagoras.phil.berkeley.edu
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAPJzDNL7FXEwiYTdC%2BtVrYQFseO6w%2BCd6%3D4BhVhdQYyuYxJM%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

[-- Attachment #2: Type: text/html, Size: 7611 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-20 21:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-18 10:57 generate a source map on html generation? Gallagher Pryor
     [not found] ` <e19a4bf3-6697-4a8b-bb57-6c99cfecbb9c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2013-10-18 19:52   ` John MacFarlane
     [not found]     ` <20131018195258.GA75103-9Rnp8PDaXcadBw3G0RLmbRFnWt+6NQIA@public.gmane.org>
2013-10-18 21:40       ` John MacFarlane
     [not found]         ` <20131018214049.GA8345-nFAEphtLEs+AA6luYCgp0U1S2cYJDpTV9nwVQlTi/Pw@public.gmane.org>
2013-10-20 21:06           ` Gallagher Pryor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).