/******************************************************************************* * Copyright (c) 2015 David Green. * 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: * David Green - initial API and implementation *******************************************************************************/ package org.eclipse.mylyn.wikitext.commonmark.internal.spec; import java.io.Writer; import org.eclipse.mylyn.wikitext.parser.Attributes; import org.eclipse.mylyn.wikitext.parser.ImageAttributes; import org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder; import com.google.common.base.Objects; public class SimplifiedHtmlDocumentBuilder extends HtmlDocumentBuilder { public SimplifiedHtmlDocumentBuilder(Writer out) { super(out, false); setFilterEntityReferences(true); } @Override public void image(Attributes attributes, String url) { writer.writeEmptyElement(getHtmlNsUri(), "img"); //$NON-NLS-1$ writer.writeAttribute("src", makeUrlAbsolute(url)); //$NON-NLS-1$ if (attributes instanceof ImageAttributes) { ImageAttributes imageAttributes = (ImageAttributes) attributes; writer.writeAttribute(getHtmlNsUri(), "alt", Objects.firstNonNull(imageAttributes.getAlt(), "")); if (imageAttributes.getTitle() != null) { writer.writeAttribute(getHtmlNsUri(), "title", imageAttributes.getTitle()); } } } @Override public void entityReference(String entity) { // TODO Auto-generated method stub super.entityReference(entity); } }