Edgewall Software
Modify

Opened 14 years ago

Closed 8 years ago

#3275 closed enhancement (duplicate)

Show line numbers when embedding source code in wiki pages

Reported by: erik@… Owned by: Christian Boos
Priority: high Milestone:
Component: wiki system Version: 0.9.5
Severity: normal Keywords: line number annotate wikiprocessor bitesized
Cc: Thijs Triemstra Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Hi

When embedding sourcecode in wiki pages using the {{{-Makro, I would sometimes like to have line numbers displayed. This would make it possible to reference some lines in a text, like:

We got some c-sourcecode here, in line 1, a buffer is allocated, in line 35, some data is copied to the buffer without checking the size of the data…

The svn browser shows line numbers, so I hope this will not be so difficult.

Attachments (1)

3275_linenumbers_inline.jpg (33.4 KB ) - added by Nelson Brown <brownnrl@…> 8 years ago.
An example of what code blocks with annotated line numbers can look in a wiki block with some other content around it for context.

Download all attachments as: .zip

Change History (11)

comment:1 by sid, 14 years ago

Essentially the ability to replicate the browser view in WikiProcessors. This could be useful, although the syntax might be unwieldy.

One idea to kick things off:

{{{
#!c +line-numbers
... C code ...
}}}

comment:2 by Christian Boos, 14 years ago

Keywords: annotate wikiprocessor added; wiki removed
Milestone: 0.11
Owner: changed from Jonas Borgström to Christian Boos

I once did that, now I have to find where I put the patch ;)

comment:3 by Christian Boos, 13 years ago

Milestone: 0.110.12

Patch was lost ;-)

WikiEngine refactoring and related fixes postponed.

comment:4 by Christian Boos, 10 years ago

Keywords: bitesized added
Priority: normalhigh

comment:5 by Thijs Triemstra <lists@…>, 10 years ago

Cc: lists@… added

I like this syntax Sphinx uses for this.

comment:6 by janoscharlipp@…, 9 years ago

Is there a workaround for this?

comment:7 by chriswillmorris@…, 9 years ago

Is this feature available?

by Nelson Brown <brownnrl@…>, 8 years ago

Attachment: 3275_linenumbers_inline.jpg added

An example of what code blocks with annotated line numbers can look in a wiki block with some other content around it for context.

comment:8 by Nelson Brown <brownnrl@…>, 8 years ago

So this is my first crack at contributing to an open source project. I basically read the recommendation that you bite into a bitesized ticket and this was the first one I saw. So what follows is some analysis, and I'd like to get a recommendation from anyone interested. The current mechanism for parsing arguments to WikiProcessors is the parse_processor_args method in trac.wiki.parser module. These currently get stored into self.args as a dictionary of key value paris in the form of processorarg=processorargvalue. So utilizing the existing syntax for passing processor arguments, an example code block with annotated line numbers might look like this: !{{{#!python annotations=lineno import something something.somethingelse() }}} This currently renders (with the arguments ignored) as:

import something
something.somethingelse()

But with the following change to source:trunk/trac/wiki/formatter.py@10865#L321

  • formatter.py

     
    321321                                                    text)
    322322
    323323    def _mimeview_processor(self, text):
    324         return Mimeview(self.env).render(self.formatter.context,
    325                                          self.name, text)
     324        annotations = self.args['annotations'] \
     325        if 'annotations' in self.args and \
     326        self.args['annotations'] in ['lineno'] \
     327        else None
     328       
     329       
     330        if annotations:
     331            return Mimeview(self.env).render(self.formatter.context,
     332                                             self.name, text,
     333                                             annotations=[annotations])
     334        else:
     335            return Mimeview(self.env).render(self.formatter.context,
     336                                             self.name, text)
    326337    # TODO: use convert('text/html') instead of render
    327338
    328339    def process(self, text, in_paragraph=False):

It would render as follows (attached image):

An example of what code blocks with annotated line numbers can look in a wiki block with some other content around it for context. So this is nice, but there are some issues with it. The anchors need to be provided with more context. The line number annoatator was designed for the display of single files, but the anchor needs to know not just the URL, but the comment # / description # / code block # / etc. The link to the eighth line in the fourth code block on the fifth comment might look something like this: #comment:5:codeblock:4:L8. Or something shorter? #c5:cb4:L8 This would mean analyzing the way arguments are passed around to annotator objects, and how to provide that contextual information. This would increase the risk associated with the change as it would be broader. Also, with possible (?) changes to the WikiEngine, I don't know if that is wise? Although this is much less a parsing issue in my (limited) view, but more of a message /argument passing issue. I'll start looking into how to best pass that contextual information, and provide a patch with included tests. I'm all for any feedback though. :)

comment:9 by Thijs Triemstra, 8 years ago

Cc: Thijs Triemstra added; lists@… removed

comment:10 by Christian Boos, 8 years ago

Milestone: next-major-releases
Resolution: duplicate
Status: newclosed

The topic was revived recently in #10834. Closing in favor of the most recent ticket.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.