/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const AstMd=require("../lib/AstMd");const FILETYPE=require("./filetypes");class Md{constructor(parser,nd,rules,fileIndex,appCtx,msgCtx){this._parser=parser;this._rules=rules;this._Issue=appCtx.Issue;this._reporter=appCtx.reporter;this._utils=appCtx.utils;this._msgCtx=msgCtx;this._nd=nd;this._Ast=null;this._data=null;this._AstMd=new AstMd(appCtx)}parse(data,file){var suppData,rc;this._data=data;this._Ast=this._AstMd.parse(data,{});suppData={ast:this._Ast,utils:this._AstMd.createHandler()};rc=this._parser.fireHookFileRules(suppData.ast,suppData,false);if(typeof rc==="undefined"||typeof rc==="boolean"&&rc){this._fireMdEvents(suppData,file)}this._parser.fireHookFileRules(null,null)}getAst(){return this._Ast}clear(){this._Ast=null}_fireMdEvents(suppData,file){var data,prop,obj,val,utils=suppData.utils;data=utils.getLinks();data.forEach(link=>{this._fireEvent("md-link",link,suppData,file)});data=utils.getRefLinks();obj={};for(prop in data){val=data[prop];obj.refKey=prop;obj.link=val.link;obj.pos=val.pos;this._fireEvent("md-ref",obj,suppData,file)}data=utils.getParas();data.forEach(para=>{this._fireEvent("md-para",para,suppData,file)});data=utils.getImages();data.forEach(img=>{this._fireEvent("md-image",img,suppData,file)});data=utils.getLists();data.forEach(list=>{this._fireEvent("md-list",list,suppData,file)});data=utils.getCode();data.forEach(code=>{this._fireEvent("md-code",code,suppData,file)})}_fireEvent(type,arg1,suppData,file){this._rules.fireRules({type:type,obj:suppData,tagNode:null,rawData:this._rawData,data:this._data,suppData:suppData},arg1,file,FILETYPE.MD,suppData,false)}}module.exports=Md;