KiCad PCB EDA Suite
html_link_parser.h
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 /*
29  * wxWidgets gives very few info about wxwebkit. For more info and more comments:
30  * see https://forums.wxwidgets.org/viewtopic.php?f=1&t=1119#
31  */
32 
33 #ifndef HTML_LINK_PARSE_H
34 #define HTML_LINK_PARSE_H
35 
36 
37 #include <wx/wx.h>
38 #include <wx/html/htmlpars.h>
39 
40 class HTML_LINK_PARSER ;
41 
50 class LINK_TAGHANDLER : public wxHtmlTagHandler
51 {
53 
54 public:
55  LINK_TAGHANDLER() : m_Parser( NULL )
56  {
57  }
58 
59  LINK_TAGHANDLER( HTML_LINK_PARSER* aParser ) : m_Parser( aParser )
60  {
61  }
62 
63  wxString GetSupportedTags() override
64  {
65  return "A";
66  }
67 
68  bool HandleTag(const wxHtmlTag& tag) override;
69 };
70 
75 class HTML_LINK_PARSER : public wxHtmlParser
76 {
77  const wxString& m_src; // the html text to parse
78  wxArrayString& stringUrls; // the strings extracted from html text
79  bool (*m_filter)( const wxString& aData ); // a callback function to filter strings
80 
81 public:
82 
83  HTML_LINK_PARSER( const wxString& aSrc, wxArrayString& aUrls );
84 
91  void ParseLinks( bool (*aFilter)( const wxString& aData ) )
92  {
93  m_filter = aFilter;
94  Parse(m_src);
95  }
96 
97  // virtual pure from wxHtmlParser, do nothing here, but needed.
98  void AddText( const wxString& aText ) override {}
99 
100  // Our "AddText" used to store selected text (the url link)
101  void AddString( const wxString& aText );
102 
103  wxObject* GetProduct() override
104  {
105  return NULL;
106  }
107 };
108 
109 #endif // ifndef HTML_LINK_PARSE_H