当前位置: 首页>>代码示例>>Java>>正文


Java SnuggleParseException类代码示例

本文整理汇总了Java中uk.ac.ed.ph.snuggletex.internal.SnuggleParseException的典型用法代码示例。如果您正苦于以下问题:Java SnuggleParseException类的具体用法?Java SnuggleParseException怎么用?Java SnuggleParseException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SnuggleParseException类属于uk.ac.ed.ph.snuggletex.internal包,在下文中一共展示了SnuggleParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseInput

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
/**
 * Parses the data contained within the given {@link SnuggleInput}, and performs fixing
 * on the resulting tokens.
 * 
 * @param snuggleInput input to parse, which must not be null
 * 
 * @return true if parsing finished, false if it was terminated by an error in the
 *   input LaTeX and if the session was configured to fail on the first error.
 */
public boolean parseInput(SnuggleInput snuggleInput) throws IOException {
    ConstraintUtilities.ensureNotNull(snuggleInput, "snuggleInput");
    /* Perform tokenisation, then fix up and store the results */
    try {
        SnuggleInputReader reader = new SnuggleInputReader(this, snuggleInput);
        RootToken rootToken = tokeniser.tokenise(reader);
        styleEvaluator.evaluateStyles(rootToken);
        tokenFixer.fixTokenTree(rootToken);
        styleRebuilder.rebuildStyles(rootToken);
        parsedTokens.addAll(rootToken.getContents());
    }
    catch (SnuggleParseException e) {
        return false;
    }
    return true;
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:26,代码来源:SnuggleSession.java

示例2: buildParagraph

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
/**
 * Builds a single paragraph, being careful to consider how best to represent it in the output
 * tree at the existing position.
 * 
 * @param builder
 * @param parentElement
 * @param inlineContent
 * @throws DOMException
 * @throws SnuggleParseException
 */
private void buildParagraph(DOMBuilder builder, Element parentElement, List<FlowToken> inlineContent)
        throws SnuggleParseException {
    Element resultElement;
    boolean isInline;
    if (builder.isBuildingMathMLIsland()) {
        /* Paragraphs inside MathML are not allowed!
         * 
         * So we won't create an element. Instead, once building reaching the text content,
         * it will be wrapped inside an <mtext/>
         */
        resultElement = parentElement;
        isInline = true;
    }
    else {
        resultElement = builder.appendXHTMLElement(parentElement, "p");
        isInline = false;
    }
    
    /* Handle content */
    builder.handleTokens(resultElement, inlineContent, !isInline);
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:32,代码来源:ParagraphHandler.java

示例3: handleCommand

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
public void handleCommand(DOMBuilder builder, Element parentElement, CommandToken token)
        throws SnuggleParseException {
    /* Extract required link target and resolve */
    String href = token.getArguments()[0].getSlice().extract().toString();
    URI resolvedLink = builder.resolveLink(parentElement, token, href);
    if (resolvedLink==null) {
        /* Bad link - error will have been appended so do nothing here */
        return;
    }
    
    /* Create <a> element with correct href attribute */
    Element aElement = builder.appendXHTMLElement(parentElement, "a");
    aElement.setAttribute("href", resolvedLink.toString());
    
    /* Now show link text, which is other provided explicitly via optional argument or
     * will just be the same as the 'href'
     */
    ArgumentContainerToken optionalArgument = token.getOptionalArgument();
    if (optionalArgument!=null) {
        builder.handleTokens(aElement, optionalArgument, true);
    }
    else {
        builder.appendTextNode(aElement, href, true);
    }
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:26,代码来源:HrefHandler.java

示例4: handleCommand

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
public void handleCommand(DOMBuilder builder, Element parentElement, CommandToken token)
        throws SnuggleParseException {
    /* We just descend into contents - \mbox doesn't actually "do" anything to the output
     * though its children will output different things because of a combination of being
     * in LR mode and the XML application the parent element belongs.
     */
    Element containerElement;
    if (builder.isBuildingMathMLIsland()) {
        containerElement = builder.appendMathMLElement(parentElement, "mrow");
    }
    else {
        containerElement = builder.appendXHTMLElement(parentElement, "span");
        builder.applyCSSStyle(containerElement, xhtmlClassName);
    }
    builder.handleTokens(containerElement, token.getArguments()[0], false);
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:17,代码来源:BoxHandler.java

示例5: handleEnvironment

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
public void handleEnvironment(DOMBuilder builder, Element parentElement, EnvironmentToken token)
        throws SnuggleParseException {
    /* Create <mfenced> element with correct attributes */
    ArgumentContainerToken contentContainer = token.getContent();
    String opener = getBracket(token.getArguments()[0]);
    String closer = getBracket(token.getArguments()[1]);
    if (opener!=null && closer!=null) {
        /* Have explicit opener and closer so can make a proper <mfenced/> */
        makeMfenced(builder, parentElement, contentContainer, opener, closer);
    }
    else {
        /* Spec says we've not to do <mfenced/> if missing an opener or closer so we
         * revert to long form here.
         */
        makeBracketed(builder, parentElement, contentContainer, opener, closer);
    }
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:18,代码来源:MathFenceHandler.java

示例6: makeMfenced

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
private void makeMfenced(DOMBuilder builder, Element parentElement,
        ArgumentContainerToken contentContainer, String opener, String closer)
        throws SnuggleParseException {
    /* Create <mfenced/> operator */
    Element mfenced = builder.appendMathMLElement(parentElement, "mfenced");
    mfenced.setAttribute("open", StringUtilities.emptyIfNull(opener));
    mfenced.setAttribute("close", StringUtilities.emptyIfNull(closer));
    
    /* Now add contents, grouping on comma operators */
    List<FlowToken> groupBuilder = new ArrayList<FlowToken>();
    for (FlowToken contentToken : contentContainer) {
        if (contentToken.getMathCharacterCodePoint()==',') {
            /* Found a comma, so add Node based on what's been found so far */
            makeFenceGroup(builder, mfenced, groupBuilder);
            groupBuilder.clear();
        }
        else {
            /* Add to group */
            groupBuilder.add(contentToken);
        }
    }
    /* Deal with what's left in the group, if appropriate */
    if (!groupBuilder.isEmpty()) {
        makeFenceGroup(builder, mfenced, groupBuilder);
    }
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:27,代码来源:MathFenceHandler.java

示例7: makeBracketed

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
private void makeBracketed(DOMBuilder builder, Element parentElement,
        ArgumentContainerToken contentContainer, String opener, String closer)
        throws SnuggleParseException {
    /* We'll be putting everything in an <mrow/> here */
    Element mrow = builder.appendMathMLElement(parentElement, "mrow");
    
    /* Maybe do an open bracket */
    if (opener!=null) {
        builder.appendMathMLOperatorElement(mrow, opener);
    }
    /* Then add contents as-is */
    for (FlowToken contentToken : contentContainer) {
        builder.handleToken(mrow, contentToken);
    }
    /* Finally, maybe do a close bracket */
    if (closer!=null) {
        builder.appendMathMLOperatorElement(mrow, closer);
    }
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:20,代码来源:MathFenceHandler.java

示例8: handleCommand

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
public void handleCommand(DOMBuilder builder, Element parentElement, CommandToken token)
        throws SnuggleParseException {
    if (builder.isBuildingMathMLIsland()) {
        throw new SnuggleLogicException("This handler is not intended for use in MathML islands");
    }
    
    /* Is the content block or inline? */
    ArgumentContainerToken contentContainerToken = token.getArguments()[0];
    boolean hasBlockContent = false;
    for (FlowToken contentToken : contentContainerToken) {
        if (contentToken.getTextFlowContext()==TextFlowContext.START_NEW_XHTML_BLOCK) {
            hasBlockContent = true;
        }
    }
    
    Element result = builder.appendXHTMLElement(parentElement, hasBlockContent ? "div" : "span");
    builder.applyCSSStyle(result, cssClassName);
    builder.handleTokens(result, contentContainerToken, false);
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:20,代码来源:TextClassHandler.java

示例9: handleCommand

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
public void handleCommand(DOMBuilder builder, Element parentElement, CommandToken token)
        throws SnuggleParseException {
    /*
     * First of all, decode the given length and convert to an appropriate
     * unit for CSS/MathML.
     */
    String resultSize = convertLaTeXSize(builder, parentElement, token.getArguments()[0]);
    if (resultSize==null) {
        /* Couldn't grok the size so do nothing */
        return;
    }
    if (token.getLatexMode() == LaTeXMode.MATH) {
        /* Create <mspace/> */
        Element mspace = builder.appendMathMLElement(parentElement, "mspace");
        mspace.setAttribute("width", resultSize);
    }
    else {
        /* Text mode, we'll cheat with a <span/> and a bit of CSS */
        Element span = builder.appendXHTMLElement(parentElement, "span");
        span.setAttribute("style", "margin-left:" + resultSize + ";font-size:0");
        builder.appendTextNode(span, "\u00a0", false);
    }
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:24,代码来源:HSpaceHandler.java

示例10: handleCommand

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
public void handleCommand(DOMBuilder builder, Element parentElement, CommandToken token)
        throws SnuggleParseException {
    ArgumentContainerToken nameArgument = token.getArguments()[0];
    String rawName = nameArgument.getSlice().extract().toString().trim();

    /* Call back on DOMBuilder to validate the name/ID */
    String result;
    if (checkType==ID) {
        result = builder.validateXMLId(parentElement, nameArgument, rawName);
    }
    else {
        result = builder.validateXMLName(parentElement, nameArgument, rawName);
    }
    
    if (result!=null) {
        /* Name was OK, so append to output as normal */
        builder.appendTextNode(parentElement, rawName, true);
    }
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:20,代码来源:XMLNameOrIdHandler.java

示例11: handleCommand

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
public void handleCommand(DOMBuilder builder, Element parentElement, CommandToken token)
        throws SnuggleParseException {
    ArgumentContainerToken nameArgument = token.getArguments()[0];
    String hexCode = nameArgument.getSlice().extract().toString().trim();
    
    try {
        int codePoint = Integer.parseInt(hexCode, 16);
        if (codePoint >= Character.MIN_VALUE && codePoint <= Character.MAX_VALUE) {
            builder.appendTextNode(parentElement, String.valueOf((char) codePoint), true);
        }
        else {
            /* Error: Unicode code point is out of the supported range */
            builder.appendOrThrowError(parentElement, token, CoreErrorCode.TDEXU1, hexCode);
        }
    }
    catch (NumberFormatException e) {
        /* Error: Unicode code point was expected to be hexadecimal */
        builder.appendOrThrowError(parentElement, token, CoreErrorCode.TDEXU0, hexCode);
    }
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:21,代码来源:InsertUnicodeHandler.java

示例12: handleEnvironment

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
/**
 * Builds the actual List environment
 */
public void handleEnvironment(DOMBuilder builder, Element parentElement, EnvironmentToken token)
        throws SnuggleParseException {
    String listElementName = null;
    BuiltinEnvironment environment = token.getEnvironment();
    if (environment==CorePackageDefinitions.ENV_ITEMIZE) {
        listElementName = "ul";
    }
    else if (environment==CorePackageDefinitions.ENV_ENUMERATE) {
        listElementName = "ol";
    }
    else {
        throw new SnuggleLogicException("No logic to handle list environment " + environment.getTeXName());
    }
    Element listElement = builder.appendXHTMLElement(parentElement, listElementName);
    handleListContent(builder, parentElement, listElement, token.getContent().getContents());
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:20,代码来源:ListEnvironmentHandler.java

示例13: handleListContent

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
private void handleListContent(DOMBuilder builder, Element parentElement, Element listElement,
        List<FlowToken> content)
        throws SnuggleParseException {
    for (FlowToken token : content) {
        if (token.isCommand(CorePackageDefinitions.CMD_LIST_ITEM)) {
            /* Good list item */
            handleListItem(builder, listElement, (CommandToken) token);
        }
        else if (token.getType()==TokenType.ERROR) {
            /* We'll append errors immediately *after* the list element */
            builder.handleToken(parentElement, token);
        }
        else {
            /* List environments should only contain list items. This should have
             * been sorted at token fixing so we've got a logic fault if we get here!
             */
            throw new SnuggleLogicException("List environments can only contain list items - this should have been handled earlier");
        }
    }
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:21,代码来源:ListEnvironmentHandler.java

示例14: handleCommand

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
public void handleCommand(DOMBuilder builder, Element parentElement, CommandToken token)
        throws SnuggleParseException {
    ArgumentContainerToken optionalArgument = token.getOptionalArgument();
    ArgumentContainerToken requiredArgument = token.getArguments()[0];
    Element result;
    if (optionalArgument!=null) {
        /* Has optional argument, so generate <mroot/> */
        result = builder.appendMathMLElement(parentElement, "mroot");
        builder.handleMathTokensAsSingleElement(result, requiredArgument);
        builder.handleMathTokensAsSingleElement(result, optionalArgument);
    }
    else {
        /* No optional argument, so do <msqrt/> */
        result = builder.appendMathMLElement(parentElement, "msqrt");
        builder.handleMathTokensAsSingleElement(result, requiredArgument);
    }
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:18,代码来源:MathRootHandler.java

示例15: handle

import uk.ac.ed.ph.snuggletex.internal.SnuggleParseException; //导入依赖的package包/类
private void handle(DOMBuilder builder, Element parentElement, 
        final ArgumentContainerToken content, final boolean isBlock)
        throws SnuggleParseException {
    /* Build children as normal */
    builder.handleTokens(parentElement, content, true);
    
    /* Serialize child content to text and replace all children with this text inside
     * an appropriate container  */
    SerializationSpecifier options = new SerializationOptions();
    options.setIndenting(isBlock);
    options.setEncoding("UTF-8");
    String parentContentUnparsed = XMLUtilities.serializeNodeChildren(builder.getSessionContext().getStylesheetManager(),
            parentElement, options);
    NodeList childNodes = parentElement.getChildNodes();
    for (int i=childNodes.getLength()-1; i>=0; i--) {
        parentElement.removeChild(childNodes.item(i));
    }
    Element resultElement = builder.appendXHTMLTextElement(parentElement,
            isBlock ? "pre" : "span",
            parentContentUnparsed, true);
    resultElement.setAttribute("class", "unparsed-xml");
}
 
开发者ID:ktisha,项目名称:snuggletex,代码行数:23,代码来源:XMLUnparseHandler.java


注:本文中的uk.ac.ed.ph.snuggletex.internal.SnuggleParseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。