📄 tidy.java
字号:
/**
* LogicalEmphasis - replace i by em and b by strong
* @see org.w3c.tidy.Configuration#LogicalEmphasis
*/
public void setLogicalEmphasis(boolean LogicalEmphasis)
{
configuration.LogicalEmphasis = LogicalEmphasis;
}
public boolean getLogicalEmphasis()
{
return configuration.LogicalEmphasis;
}
/**
* XmlPIs - if set to true PIs must end with ?>
* @see org.w3c.tidy.Configuration#XmlPIs
*/
public void setXmlPIs(boolean XmlPIs)
{
configuration.XmlPIs = XmlPIs;
}
public boolean getXmlPIs()
{
return configuration.XmlPIs;
}
/**
* EncloseText - if true text at body is wrapped in <p>'s
* @see org.w3c.tidy.Configuration#EncloseBodyText
*/
public void setEncloseText(boolean EncloseText)
{
configuration.EncloseBodyText = EncloseText;
}
public boolean getEncloseText()
{
return configuration.EncloseBodyText;
}
/**
* EncloseBlockText - if true text in blocks is wrapped in <p>'s
* @see org.w3c.tidy.Configuration#EncloseBlockText
*/
public void setEncloseBlockText(boolean EncloseBlockText)
{
configuration.EncloseBlockText = EncloseBlockText;
}
public boolean getEncloseBlockText()
{
return configuration.EncloseBlockText;
}
/**
* KeepFileTimes - if true last modified time is preserved<br>
* <b>this is NOT supported at this time.</b>
* @see org.w3c.tidy.Configuration#KeepFileTimes
*/
public void setKeepFileTimes(boolean KeepFileTimes)
{
configuration.KeepFileTimes = KeepFileTimes;
}
public boolean getKeepFileTimes()
{
return configuration.KeepFileTimes;
}
/**
* Word2000 - draconian cleaning for Word2000
* @see org.w3c.tidy.Configuration#Word2000
*/
public void setWord2000(boolean Word2000)
{
configuration.Word2000 = Word2000;
}
public boolean getWord2000()
{
return configuration.Word2000;
}
/**
* TidyMark - add meta element indicating tidied doc
* @see org.w3c.tidy.Configuration#TidyMark
*/
public void setTidyMark(boolean TidyMark)
{
configuration.TidyMark = TidyMark;
}
public boolean getTidyMark()
{
return configuration.TidyMark;
}
/**
* XmlSpace - if set to yes adds xml:space attr as needed
* @see org.w3c.tidy.Configuration#XmlSpace
*/
public void setXmlSpace(boolean XmlSpace)
{
configuration.XmlSpace = XmlSpace;
}
public boolean getXmlSpace()
{
return configuration.XmlSpace;
}
/**
* Emacs - if true format error output for GNU Emacs
* @see org.w3c.tidy.Configuration#Emacs
*/
public void setEmacs(boolean Emacs)
{
configuration.Emacs = Emacs;
}
public boolean getEmacs()
{
return configuration.Emacs;
}
/**
* LiteralAttribs - if true attributes may use newlines
* @see org.w3c.tidy.Configuration#LiteralAttribs
*/
public void setLiteralAttribs(boolean LiteralAttribs)
{
configuration.LiteralAttribs = LiteralAttribs;
}
public boolean getLiteralAttribs()
{
return configuration.LiteralAttribs;
}
/**
* InputStreamName - the name of the input stream (printed in the
* header information).
*/
public void setInputStreamName(String name)
{
if (name != null)
inputStreamName = name;
}
public String getInputStreamName()
{
return inputStreamName;
}
/**
* Sets the configuration from a configuration file.
*/
public void setConfigurationFromFile(String filename)
{
configuration.parseFile(filename);
}
/**
* Sets the configuration from a properties object.
*/
public void setConfigurationFromProps(Properties props)
{
configuration.addProps(props);
}
/**
* first time initialization which should
* precede reading the command line
*/
private void init()
{
configuration = new Configuration();
if (configuration == null) return;
AttributeTable at = AttributeTable.getDefaultAttributeTable();
if (at == null) return;
TagTable tt = TagTable.getDefaultTagTable();
if (tt == null) return;
tt.setConfiguration(configuration);
EntityTable et = EntityTable.getDefaultEntityTable();
if (et == null) return;
/* Unnecessary - same initial values in Configuration
Configuration.XmlTags = false;
Configuration.XmlOut = false;
Configuration.HideEndTags = false;
Configuration.UpperCaseTags = false;
Configuration.MakeClean = false;
Configuration.writeback = false;
Configuration.OnlyErrors = false;
*/
configuration.errfile = null;
stderr = new PrintWriter(System.err, true);
errout = stderr;
initialized = true;
}
/**
* Parses InputStream in and returns the root Node.
* If out is non-null, pretty prints to OutputStream out.
*/
public Node parse(InputStream in, OutputStream out)
{
Lexer lexer;
Node document = null;
Node doctype;
Out o = new OutImpl(); /* normal output stream */
PPrint pprint;
if (!initialized)
return null;
if (errout == null)
return null;
parseErrors = 0;
parseWarnings = 0;
/* ensure config is self-consistent */
configuration.adjust();
if (in != null)
{
lexer = new Lexer(new StreamInImpl(in,
configuration.CharEncoding,
configuration.tabsize),
configuration);
lexer.errout = errout;
/*
store pointer to lexer in input stream
to allow character encoding errors to be
reported
*/
lexer.in.lexer = lexer;
/* Tidy doesn't alter the doctype for generic XML docs */
if (configuration.XmlTags)
document = ParserImpl.parseXMLDocument(lexer);
else
{
lexer.warnings = 0;
if (!configuration.Quiet)
Report.helloMessage(errout, Report.RELEASE_DATE, inputStreamName);
document = ParserImpl.parseDocument(lexer);
if (!document.checkNodeIntegrity())
{
Report.badTree(errout);
return null;
}
/* simplifies <b><b> ... </b> ...</b> etc. */
Clean.nestedEmphasis(document);
/* cleans up <dir>indented text</dir> etc. */
Clean.list2BQ(document);
Clean.bQ2Div(document);
/* replaces i by em and b by strong */
if (configuration.LogicalEmphasis)
Clean.emFromI(document);
if (configuration.Word2000 && Clean.isWord2000(document))
{
/* prune Word2000's <![if ...]> ... <![endif]> */
Clean.dropSections(lexer, document);
/* drop style & class attributes and empty p, span elements */
Clean.cleanWord2000(lexer, document);
}
/* replaces presentational markup by style rules */
if (configuration.MakeClean || configuration.DropFontTags)
(new Clean()).cleanTree(lexer, document);
if (!document.checkNodeIntegrity())
{
Report.badTree(errout);
return null;
}
doctype = document.findDocType();
if (document.content != null)
{
if (configuration.xHTML)
lexer.setXHTMLDocType(document);
else
lexer.fixDocType(document);
if (configuration.TidyMark)
lexer.addGenerator(document);
}
/* ensure presence of initial <?XML version="1.0"?> */
if (configuration.XmlOut && configuration.XmlPi)
lexer.fixXMLPI(document);
if (!configuration.Quiet && document.content != null)
{
Report.reportVersion(errout, lexer, inputStreamName, doctype);
Report.reportNumWarnings(errout, lexer);
}
}
parseWarnings = lexer.warnings;
parseErrors = lexer.errors;
if (lexer.errors > 0)
Report.needsAuthorIntervention(errout);
o.state = StreamIn.FSM_ASCII;
o.encoding = configuration.CharEncoding;
if (out != null && !configuration.OnlyErrors && lexer.errors == 0)
{
pprint = new PPrint(configuration);
/* NOTE:
Configuration.BurstSlides and Configuration.writeback
are NOT supported when parsing from an InputStream.
*/
o.out = out;
if (configuration.XmlTags)
pprint.printXMLTree(o, (short)0, 0, lexer, document);
else
pprint.printTree(o, (short)0, 0, lexer, document);
pprint.flushLine(o, 0);
}
Report.errorSummary(lexer);
}
return document;
}
/**
* Parses InputStream in and returns a DOM Document node.
* If out is non-null, pretty prints to OutputStream out.
*/
public org.w3c.dom.Document parseDOM(InputStream in, OutputStream out)
{
Node document = parse(in, out);
if (document != null)
return (org.w3c.dom.Document)document.getAdapter();
else
return null;
}
/**
* Creates an empty DOM Document.
*/
public static org.w3c.dom.Document createEmptyDocument()
{
Node document = new Node(Node.RootNode, new byte[0], 0, 0);
Node node = new Node(Node.StartTag, new byte[0], 0, 0, "html");
if (document != null && node != null)
{
Node.insertNodeAtStart(document, node);
return (org.w3c.dom.Document)document.getAdapter();
} else {
return null;
}
}
/**
* Pretty-prints a DOM Document.
*/
public void pprint(org.w3c.dom.Document doc, OutputStream out)
{
Out o = new OutImpl();
PPrint pprint;
Node document;
if (!(doc instanceof DOMDocumentImpl)) {
return;
}
document = ((DOMDocumentImpl)doc).adaptee;
o.state = StreamIn.FSM_ASCII;
o.encoding = configuration.CharEncoding;
if (out != null)
{
pprint = new PPrint(configuration);
o.out = out;
if (configuration.XmlTags)
pprint.printXMLTree(o, (short)0, 0, null, document);
else
pprint.printTree(o, (short)0, 0, null, document);
pprint.flushLine(o, 0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -