mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 13:40:44 +00:00
Add QHelpContentPlugin, so that supplemental instance meta data can accept help content. also add commonmark dep and getContentAsHtml method
This commit is contained in:
@ -36,6 +36,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.helpcontent.HelpContent;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QSupplementalInstanceMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.help.HelpFormat;
|
||||
@ -163,6 +164,23 @@ public class QInstanceHelpContentManager
|
||||
{
|
||||
processHelpContentForInstance(qInstance, key, slotName, roles, helpContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(QSupplementalInstanceMetaData supplementalInstanceMetaData : qInstance.getSupplementalMetaData().values())
|
||||
{
|
||||
if(supplementalInstanceMetaData instanceof QHelpContentPlugin helpContentPlugin)
|
||||
{
|
||||
try
|
||||
{
|
||||
helpContentPlugin.acceptHelpContent(qInstance, helpContent, nameValuePairs);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.warn("Error processing a helpContent record in a helpContentPlugin", e, logPair("pluginName", supplementalInstanceMetaData.getName()), logPair("id", record.getValue("id")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -26,10 +26,13 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QMetaDataObject;
|
||||
import org.commonmark.node.Node;
|
||||
import org.commonmark.parser.Parser;
|
||||
import org.commonmark.renderer.html.HtmlRenderer;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** meta-data defintion of "Help Content" to show to a user - for use in
|
||||
** meta-data definition of "Help Content" to show to a user - for use in
|
||||
** a specific "role" (e.g., insert screens but not view screens), and in a
|
||||
** particular "format" (e.g., plain text, html, markdown).
|
||||
**
|
||||
@ -48,6 +51,12 @@ public class QHelpContent implements QMetaDataObject
|
||||
private HelpFormat format;
|
||||
private Set<HelpRole> roles;
|
||||
|
||||
////////////////////////////////////
|
||||
// these appear to be thread safe //
|
||||
////////////////////////////////////
|
||||
private static Parser commonMarkParser = Parser.builder().build();
|
||||
private static HtmlRenderer commonMarkRenderer = HtmlRenderer.builder().build();
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -71,6 +80,38 @@ public class QHelpContent implements QMetaDataObject
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* Return the content as html string, based on its format.
|
||||
* Only MARKDOWN actually gets processed (via commonmark) - but TEXT and
|
||||
* HTML come out as-is.
|
||||
***************************************************************************/
|
||||
public String getContentAsHtml()
|
||||
{
|
||||
if(content == null)
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
|
||||
if(HelpFormat.MARKDOWN.equals(this.format))
|
||||
{
|
||||
//////////////////////////////
|
||||
// convert markdown to HTML //
|
||||
//////////////////////////////
|
||||
Node document = commonMarkParser.parse(content);
|
||||
String html = commonMarkRenderer.render(document);
|
||||
return (html);
|
||||
}
|
||||
else
|
||||
{
|
||||
///////////////////////////////////////////////////
|
||||
// other formats (html & text) just output as-is //
|
||||
///////////////////////////////////////////////////
|
||||
return (content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for content
|
||||
*******************************************************************************/
|
||||
|
Reference in New Issue
Block a user