Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325006 - handle links when transforming file based wikitext to eclipse help
Summary: handle links when transforming file based wikitext to eclipse help
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Mylyn (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 2.0   Edit
Assignee: Torkild Resheim CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-10 15:28 EDT by Henrik Lindberg CLA
Modified: 2013-11-12 11:42 EST (History)
2 users (show)

See Also:


Attachments
mylyn/context/zip (2.60 KB, application/octet-stream)
2013-06-05 14:52 EDT, David Green CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Henrik Lindberg CLA 2010-09-10 15:28:09 EDT
When wikitext is transformed to eclipse help using the standalone ant task, wiki links are translated to references to the link name without appending ".html".

A an example - the input:
See [details] for more information.

Is transformed to:
See <a href="<<HELPROOT>>/details">details</a>

Minimal support for wiki links, just needs to output:

See <a href="<<HELPROOT>>/details">details</a>
Comment 1 David Green CLA 2010-09-10 17:03:57 EDT
Adding Dave Carver, who (from the newsgroup) is running into the same issue.
Comment 2 Henrik Lindberg CLA 2010-09-23 12:35:05 EDT
(In reply to comment #0)
Typo 
> Minimal support for wiki links, just needs to output:
> 
> See <a href="<<HELPROOT>>/details">details</a>

Should have been
    See <a href="<<HELPROOT>>/details.html">details</a>
Comment 3 David Carver CLA 2010-09-23 12:42:10 EDT
(In reply to comment #2)
> (In reply to comment #0)
> Typo 
> > Minimal support for wiki links, just needs to output:
> > 
> > See <a href="<<HELPROOT>>/details">details</a>
> 
> Should have been
>     See <a href="<<HELPROOT>>/details.html">details</a>

Correct I ended up having to override a the emitAnchorHref() method to append the .html to the end of the links.

So I extended HtmlDocumentBuilder and did my own implementation (really a hack).  Here is the relevant code below:


	@Override
	protected void emitAnchorHref(String href) {
		writer.writeAttribute("href", makeUrlAbsolute(href)); //$NON-NLS-1$
	}
	
	private static final Pattern ABSOLUTE_URL_PATTERN = Pattern.compile("[a-zA-Z]{3,8}://?.*"); //$NON-NLS-1$
	
	protected String makeUrlAbsolute(String url) {
		
		if (ABSOLUTE_URL_PATTERN.matcher(url).matches()) {
			return url;
		}
		if (url.startsWith("#")) { //$NON-NLS-1$
			return url;
		}
		if (url.endsWith(".jpg") || url.endsWith(".png") || url.endsWith(".gif") || url.endsWith(".JPG") || url.endsWith(".PNG") || url.endsWith(".GIF")) {
			return url;
		}
		String absoluteUrl = url + ".html";
		return absoluteUrl;
	}

Now as I said it is a hack.
Comment 4 Torkild Resheim CLA 2013-06-04 08:47:19 EDT
I need this one fixed.
Comment 5 David Green CLA 2013-06-05 14:51:28 EDT
things to consider:
# do we do this for all relative links without file extensions or just for links referencing files that are being transformed by the current Ant task?
# this should be handled correctly in the case of generation to single or multiple files (@multipleOutputFiles@ option on Ant task)
# does the implementation result in the same output when transforming source files individually as when transforming multiple source files together in a single fileset?
Comment 6 David Green CLA 2013-06-05 14:52:05 EDT
Created attachment 232007 [details]
mylyn/context/zip
Comment 7 Torkild Resheim CLA 2013-06-05 14:59:08 EDT
Thanks for your input David, I just sat down to take a second stab at this one :-)

(In reply to comment #5)
> things to consider:
> # do we do this for all relative links without file extensions or just for
> links referencing files that are being transformed by the current Ant task?
I believe all relative links. Maybe test that the source files (with wiki markup) actually exists?

> # this should be handled correctly in the case of generation to single or
> multiple files (@multipleOutputFiles@ option on Ant task)
Maybe not the same issue, rather an improvement to @multipleOutputFiles@. But definitely yes.

> # does the implementation result in the same output when transforming source
> files individually as when transforming multiple source files together in a
> single fileset?
Yes, that was my intention. I see no reason why it should not.

I noticed I broke a lot of markup language specific tests when doing my first attempt (it appears that tests are for some reason not executed locally during maven build). So I'm investigating those.
Comment 8 Torkild Resheim CLA 2013-06-05 15:15:23 EDT
I see at least most of the tests I broke expect links to be unchanged. This I think is only true if the document is still on a wiki. I this case we're handling a file based wiki, a concept that seem to be missing. 

I start to think that there should be some way of detecting a file based wiki and only do the link transformation if this is the case. Or it could be left to the user and we could simply add an option to the Ant tasks.

Lastly it would be cool if we could augment the Wiki preview browser to produce proper links between e.g. *.textile pages. So a link to @foo@ would render as a link to @foo.textile@ _and_ open in the Wiki editor (not in the browser). However that is another issue.
Comment 9 Torkild Resheim CLA 2013-06-05 16:12:22 EDT
I have some work going on at https://git.eclipse.org/r/#/c/13578/
Comment 10 Torkild Resheim CLA 2013-06-05 16:36:53 EDT
The solution now looks like this:

* Added flag to HtmlDocumentBuilder indicating whether or not such
  transformation of links should be done.
* The flag is enabled when markup is converted to HTML using one of
  the purposed Ant tasks. It will also handle generation to multiple
  destination files.
* Links that are relative and does not have a file suffix are
  transformed. Links to anchors in other files are also handled.
Comment 11 Torkild Resheim CLA 2013-06-17 08:56:02 EDT
David, unless you have any objections I would like merge the proposed change set into master.
Comment 12 David Green CLA 2013-06-17 11:35:01 EDT
Torkild, I'd like to complete the code review before it gets merged.  I'll try to get to it this week.
Comment 13 Torkild Resheim CLA 2013-06-17 15:57:10 EDT
(In reply to comment #12)
> Torkild, I'd like to complete the code review before it gets merged.  I'll try
> to get to it this week.
Great! Thanks David.
Comment 14 David Green CLA 2013-08-02 12:44:19 EDT
Closed as part of backlog clean-up.  Please re-open if you'd like to see this revisited, perhaps with a contribution.
Comment 15 Torkild Resheim CLA 2013-08-11 06:23:50 EDT
Work is ongoing. See https://git.eclipse.org/r/#/c/13578/
Comment 16 Torkild Resheim CLA 2013-11-12 11:42:09 EST
Fixed in https://git.eclipse.org/r/#/c/13578/