diff options
author | Andras Timar <atimar@suse.com> | 2013-02-12 22:32:53 +0100 |
---|---|---|
committer | Andras Timar <atimar@suse.com> | 2013-02-13 10:19:21 +0100 |
commit | 67b8c0339e90c42dca402a925a624fce67f8ea5c (patch) | |
tree | e36a9870897415f5f1f169eb7b4f543ebfc01093 /helpcompiler | |
parent | fb1f3db03df25bee8b17a85e26774e79483de791 (diff) |
fdo#41737 syntax highlighting of Basic code examples in offline help
Change-Id: I7dc5b189e98a0351bac0eab28c1161b5893f5ef1
Diffstat (limited to 'helpcompiler')
-rw-r--r-- | helpcompiler/inc/BasCodeTagger.hxx | 1 | ||||
-rw-r--r-- | helpcompiler/inc/HelpCompiler.hxx | 3 | ||||
-rw-r--r-- | helpcompiler/source/BasCodeTagger.cxx | 27 | ||||
-rw-r--r-- | helpcompiler/source/HelpCompiler.cxx | 74 |
4 files changed, 48 insertions, 57 deletions
diff --git a/helpcompiler/inc/BasCodeTagger.hxx b/helpcompiler/inc/BasCodeTagger.hxx index 3cf9261ed8db..9ff376aa8ad3 100644 --- a/helpcompiler/inc/BasCodeTagger.hxx +++ b/helpcompiler/inc/BasCodeTagger.hxx @@ -34,7 +34,6 @@ class L10N_DLLPUBLIC BasicCodeTagger BasicCodeTagger( xmlDocPtr rootDoc ); ~BasicCodeTagger(); void tagBasicCodes(); - void saveTreeToFile( const std::string& filePath, const std::string& encoding ); }; //================LibXmlTreeWalker=========================================================== diff --git a/helpcompiler/inc/HelpCompiler.hxx b/helpcompiler/inc/HelpCompiler.hxx index 034a629c25e6..8a5dda170747 100644 --- a/helpcompiler/inc/HelpCompiler.hxx +++ b/helpcompiler/inc/HelpCompiler.hxx @@ -245,7 +245,8 @@ public: const std::string &entryName, const Hashtable &bytesToAdd); private: xmlDocPtr getSourceDocument(const fs::path &filePath); - void sourceDocumentPreWorks( xmlDocPtr doc , const fs::path &filePath); + void tagBasicCodeExamples(xmlDocPtr doc); + void saveXhpForJar(xmlDocPtr doc, const fs::path &filePath); xmlNodePtr clone(xmlNodePtr node, const std::string& appl); StreamTable &streamTable; const fs::path inputFile, src, zipdir; diff --git a/helpcompiler/source/BasCodeTagger.cxx b/helpcompiler/source/BasCodeTagger.cxx index 339d96bb1ef6..585291288342 100644 --- a/helpcompiler/source/BasCodeTagger.cxx +++ b/helpcompiler/source/BasCodeTagger.cxx @@ -137,15 +137,9 @@ void BasicCodeTagger::tagParagraph( xmlNodePtr paragraph ) } //3. create new paragraph content - String strLine( - OUString( - reinterpret_cast<const sal_Char*>(codeSnippet), - strlen( - reinterpret_cast<const char*>(codeSnippet) - ), - RTL_TEXTENCODING_UTF8 - ) - ) ; + OUString strLine( reinterpret_cast<const sal_Char*>(codeSnippet), + strlen(reinterpret_cast<const char*>(codeSnippet)), + RTL_TEXTENCODING_UTF8 ); m_Highlighter.notifyChange ( 0, 0, &strLine, 1 ); HighlightPortions portions; m_Highlighter.getHighlightPortions( 0, strLine, portions ); @@ -155,7 +149,7 @@ void BasicCodeTagger::tagParagraph( xmlNodePtr paragraph ) for ( size_t i=0; i<portions.size(); i++ ) { HighlightPortion& r = portions[i]; - subStr = xmlStrsub( codeSnippet, r.nBegin, r.nEnd-r.nBegin ); + subStr = (xmlChar*) OUStringToOString( strLine.copy( r.nBegin, r.nEnd-r.nBegin ), RTL_TEXTENCODING_UTF8 ).getStr(); text = xmlNewText( subStr ); if ( r.tokenType != TT_WHITESPACE ) { @@ -185,7 +179,7 @@ void BasicCodeTagger::tagBasicCodes() { getBasicCodeContainerNodes(); } - catch (TaggerException ex) + catch (TaggerException &ex) { std::cout << "BasCodeTagger error occured. Error code:" << ex << std::endl; } @@ -229,7 +223,7 @@ xmlChar* BasicCodeTagger::getTypeString( TokenTypes tokenType ) str = "operator"; break; case TT_KEYWORDS : - str = "keywords"; + str = "keyword"; break; case TT_PARAMETER : str = "parameter"; @@ -240,12 +234,3 @@ xmlChar* BasicCodeTagger::getTypeString( TokenTypes tokenType ) } return xmlCharStrdup( str ); } - -//! Saves the current xml DOM to file with the provided libxml2 encoding string in an unformatted way. -void BasicCodeTagger::saveTreeToFile( const std::string& filePath, const std::string& encoding ) -{ - //saveDocument - int ret = xmlSaveFormatFileEnc( filePath.c_str(), m_pDocument, encoding.c_str(), 0 ); - if ( ret == -1 ) - throw FILE_WRITING; -} diff --git a/helpcompiler/source/HelpCompiler.cxx b/helpcompiler/source/HelpCompiler.cxx index 8c6f66b49977..3983f169603d 100644 --- a/helpcompiler/source/HelpCompiler.cxx +++ b/helpcompiler/source/HelpCompiler.cxx @@ -54,41 +54,50 @@ HelpCompiler::HelpCompiler(StreamTable &in_streamTable, const fs::path &in_input } } -void HelpCompiler::sourceDocumentPreWorks( xmlDocPtr doc, const fs::path &filePath ) +void HelpCompiler::tagBasicCodeExamples( xmlDocPtr doc ) { - if ( doc ) + try { - if ( module == "sbasic" ) - { - try - { - BasicCodeTagger bct( doc ); - bct.tagBasicCodes(); - } - catch ( BasicCodeTagger::TaggerException ex ) - { - if ( ex != BasicCodeTagger::EMPTY_DOCUMENT ) - throw; - } - //save document in ziptmp<modul>_<lang>/text directory - //1. construct new path - const std::string& pth = filePath.native_file_string(); - std::string sourceNativeXhpPath = pth.substr( pth.rfind( lang+"/text/" ) ).substr( lang.length() ); - std::string xhpFileName = sourceNativeXhpPath.substr( sourceNativeXhpPath.rfind( '/' ) + 1 ); - sourceNativeXhpPath = sourceNativeXhpPath.substr( 0, sourceNativeXhpPath.rfind( '/' ) ); - //2. save xml doc with the new path - // -create directory hierachy - fs::create_directory( fs::path( zipdir.native_file_string() + sourceNativeXhpPath, fs::native ) ); - // -save document - if ( -1 == xmlSaveFormatFileEnc( (zipdir.native_file_string() + sourceNativeXhpPath + '/' + xhpFileName).c_str(), doc, "utf-8", 0 ) ) - throw BasicCodeTagger::FILE_WRITING; - } + BasicCodeTagger bct( doc ); + bct.tagBasicCodes(); + } + catch ( BasicCodeTagger::TaggerException &ex ) + { + if ( ex != BasicCodeTagger::EMPTY_DOCUMENT ) + throw; } } +void HelpCompiler::saveXhpForJar( xmlDocPtr doc, const fs::path &filePath ) +{ + //save processed xhp document in ziptmp<module>_<lang>/text directory +#ifdef WNT + std::string pathSep = "\\"; +#else + std::string pathSep = "/"; +#endif + const std::string& sourceXhpPath = filePath.native_file_string(); + std::string zipdirPath = zipdir.native_file_string(); + std::string jarXhpPath = sourceXhpPath.substr( sourceXhpPath.rfind( lang + pathSep + "text" + pathSep ) ).substr( lang.length() ); + std::string xhpFileName = jarXhpPath.substr( jarXhpPath.rfind( pathSep ) + 1 ); + jarXhpPath = jarXhpPath.substr( 0, jarXhpPath.rfind( pathSep ) ); + if ( !jarXhpPath.compare( 1, 11, "text" + pathSep + "sbasic" ) ) + { + tagBasicCodeExamples( doc ); + } + if ( !jarXhpPath.compare( 1, 11, "text" + pathSep + "shared" ) ) + { + size_t pos = zipdirPath.find( "ziptmp" ) + 6; + zipdirPath.replace( pos, module.length(), "shared" ); + } + fs::create_directory( fs::path( zipdirPath + jarXhpPath, fs::native ) ); + if ( -1 == xmlSaveFormatFileEnc( (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str(), doc, "utf-8", 0 ) ) + std::cerr << "Error saving file to " << (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str() << std::endl; +} + + xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath) { - static const char *params[4 + 1]; static xsltStylesheetPtr cur = NULL; xmlDocPtr res; @@ -99,22 +108,19 @@ xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath) impl_sleep( 3 ); res = xmlParseFile(filePath.native_file_string().c_str()); } - sourceDocumentPreWorks( res, filePath ); } else { + static const char *params[2 + 1]; if (!cur) { static std::string fsroot('\'' + src.toUTF8() + '\''); - static std::string esclang('\'' + lang + '\''); xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; cur = xsltParseStylesheetFile((const xmlChar *)resEmbStylesheet.native_file_string().c_str()); int nbparams = 0; - params[nbparams++] = "Language"; - params[nbparams++] = esclang.c_str(); params[nbparams++] = "fsroot"; params[nbparams++] = fsroot.c_str(); params[nbparams] = NULL; @@ -125,8 +131,8 @@ xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath) impl_sleep( 3 ); doc = xmlParseFile(filePath.native_file_string().c_str()); } - sourceDocumentPreWorks( doc, filePath ); - //???res = xmlParseFile(filePath.native_file_string().c_str()); + + saveXhpForJar( doc, filePath ); res = xsltApplyStylesheet(cur, doc, params); xmlFreeDoc(doc); |