jelovirt / org.lwdita

LwDITA parser for DITA-OT
http://lwdita.org/
Apache License 2.0
25 stars 19 forks source link

Errors are not presented when converting Markdown to DITA #186

Closed DunaMariusCosmin closed 11 months ago

DunaMariusCosmin commented 1 year ago

I have the following TC:

String mdText = 
        "# Markdown Sample\n" + 
        "\n" + 
        "##### First section\n" + 
        "Some content inside *first section*.\n" + 
        "";

    Exception ex = new Exception();
    try {
      XMLReader reader = new MarkdownReader();
      InputSource is = new InputSource(new StringReader(mdText));
      is.setSystemId("fake.md");
      Source src = new SAXSource(reader, is);
      StringWriter sw = new StringWriter();
      Result res = new StreamResult(sw);
      Transformer newTransformer = TransformerFactoryImpl.newInstance().newTransformer();
      newTransformer.transform(src, res);
      sw.close();
      String dita = sw.toString();
      fail();
    } catch (Exception e) {
      ex = e;
    }

    assertEquals("Heading level raised from 1 to 5 without intermediate heading level", ex.getMessage());

The com.elovirta.dita.markdown.MarkdownParser.convert(BasedSequence, URI) method throws a ParseException in this case and the transformer doesn't know to handle it and doesn't preserve the exception message.

Maybe the com.elovirta.dita.markdown.MarkdownReader.parse(InputSource) method should catch the ParseException and throw a SaxException instead of it.