/*
 * 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 RULE_NAME="oj-html-invalid-doctype";function getName(){return RULE_NAME};function getShortDescription(){return"HTML page should specify 'html' in the <!doctype> declaration"};function getDescription(){return"JET requires HTML5 standards mode. To ensure that this mode is enabled in every browser, you should specify 'html' in the <!doctype> declaration"};function register(){return{"file":_handleFile}};function _handleFile(ruleCtx){var node,siblings,i;var DomUtils=ruleCtx.utils.DomUtils;var NodeType=ruleCtx.NodeTypes;node=ruleCtx.node;if(node.type===NodeType.DIRECTIVE){if(_isGoodDirective(ruleCtx,node)){return}}siblings=DomUtils.getSiblings(node);for(i=0;i<siblings.length;i++){node=siblings[i];if(node.type===NodeType.DIRECTIVE){if(_isGoodDirective(ruleCtx,node)){return}}if(node.type===NodeType.TAG||node.type===NodeType.SCRIPT){break}}};function _isGoodDirective(ruleCtx,node){var ret=false;if(_isDocType(node.data)){if(ruleCtx.utils.DomUtils.isNonFragmentJetPage(ruleCtx)){_isDocTypeHtml(ruleCtx,node);ret=true}}return ret};function _emitIssue(ruleCtx,node,id){var issue,pos,msg;ruleCtx.clearPosition();switch(id){case 1:msg="<!doctype> does not specify 'html'";break;case 2:msg="Unexpected white space between ! and 'doctype'";break}issue=new ruleCtx.Issue(msg);pos=_applyfix(ruleCtx,node);issue.setPosition(null,null,pos,pos+7);if(id===2){issue.setMsgKey(RULE_NAME+"_1")}ruleCtx.reporter.addIssue(issue,ruleCtx)};function _isDocTypeHtml(ruleCtx,node){var data=node.data.toLowerCase();if(!data.startsWith("!d")){_emitIssue(ruleCtx,node,2)}if(_getNodeData(data)!=="html"){_emitIssue(ruleCtx,node,1)}};function _isDocType(s){s=s?s.substr(1).trim().toLowerCase():s;return s.startsWith("doctype")};function _getNodeData(s){if(s){s=s.replace(/!/g,"").trim().substr(7).trim().toLowerCase()}return s};function _applyfix(ruleCtx,node){var x,i,d;x=node.startIndex;d=ruleCtx.rawData;x=ruleCtx.utils.utils.eatWhitespace(d,x);d=d.substring(x);for(i=0;i<d.length;i++){if(d.charAt(i)==="!"){return x+i}}return node.startIndex};module.exports={getName,getDescription,getShortDescription,register};