From 3602f2bde27f943a1ef83e980effe807525056d7 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Tue, 25 Jul 2017 17:41:22 +0000 Subject: [PATCH] added c++ support --- lib/adapter_learnxiny.py | 33 +++++++++++++++++++++++++++++++++ lib/cheat_wrapper.py | 1 + 2 files changed, 34 insertions(+) diff --git a/lib/adapter_learnxiny.py b/lib/adapter_learnxiny.py index d0ca261..2e6224c 100644 --- a/lib/adapter_learnxiny.py +++ b/lib/adapter_learnxiny.py @@ -118,6 +118,38 @@ class LearnClojureAdapter(LearnXYAdapter): answer = answer[:1] return answer +class LearnCppAdapter(LearnXYAdapter): + _prefix = "c++" + _filename = "c++.html.markdown" + + def _is_block_separator(self, before, now, after): + if ( re.match(r'////////*', before) + and re.match(r'// ', now) + and re.match(r'////////*', after)): + block_name = re.sub('//\s*', '', now).replace('(', '').replace(')', '') + block_name = '_'.join(block_name.strip(", ").split()) + replace_with = { + 'More_about_Objects': + 'Prototypes', + } + for k in replace_with: + if k in block_name: + block_name = replace_with[k] + return block_name + else: + return None + + @staticmethod + def _cut_block(block): + answer = block[2:-1] + if answer == []: + return answer + if answer[0].split() == '': + answer = answer[1:] + if answer[-1].split() == '': + answer = answer[:1] + return answer + class LearnElixirAdapter(LearnXYAdapter): _prefix = "elixir" _filename = "elixir.html.markdown" @@ -487,6 +519,7 @@ class LearnRubyAdapter(LearnXYAdapter): ADAPTERS = { 'clojure' : LearnClojureAdapter(), + 'cpp' : LearnCppAdapter(), 'elixir' : LearnElixirAdapter(), 'elm' : LearnElmAdapter(), 'erlang' : LearnErlangAdapter(), diff --git a/lib/cheat_wrapper.py b/lib/cheat_wrapper.py index 1fa1868..9bf821c 100644 --- a/lib/cheat_wrapper.py +++ b/lib/cheat_wrapper.py @@ -39,6 +39,7 @@ from adapter_learnxiny import get_learnxiny, get_learnxiny_list, is_valid_learnx INTERNAL_TOPICS = [":list", ":firstpage", ':post', ':bash_completion', ':help', ':styles', ':styles-demo', ':emacs', ':emacs-ivy', ':fish', ':bash', ':zsh'] LEXER = { "clojure": pygments.lexers.ClojureLexer, + "cpp" : pygments.lexers.CppLexer, "erlang": pygments.lexers.ErlangLexer, "elixir": pygments.lexers.ElixirLexer, "elm" : pygments.lexers.ElmLexer,