Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 07e6087fe8f8c29b8eaadb5a92ee3e389e7d169c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*******************************************************************************
 * Copyright (c) 2013 Stefan Seelmann and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Stefan Seelmann - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.wikitext.markdown.core.token;

import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;

/**
 * Detects automatic links: <http://www.example.com>.
 * 
 * @author Stefan Seelmann
 */
public class AutomaticLinkReplacementToken extends PatternBasedElement {

	public static final String AUTOMATIC_LINK_REGEX = "<((?:https?|ftp):[^'\">\\s]+)>"; //$NON-NLS-1$

	@Override
	protected String getPattern(int groupOffset) {
		return AUTOMATIC_LINK_REGEX;
	}

	@Override
	protected int getPatternGroupCount() {
		return 1;
	}

	@Override
	protected PatternBasedElementProcessor newProcessor() {
		return new AutomaticLinkReplacementTokenProcessor();
	}

	private static class AutomaticLinkReplacementTokenProcessor extends PatternBasedElementProcessor {
		@Override
		public void emit() {
			String href = group(1);
			builder.link(href, href);
		}
	}

}

Back to the top